88

How do I figure out what changeset I currently have in my local workspace?

Sure, I can pick one file and view its history. However, if that file was not recently updated, its changeset is probably older than the more recently updated files in the same solution.

One possible mistake that we may make is that we view the history on the solution file, however the solution file rarely changes unless you're adding a new project / making solution-level changes.

In the end to figure out the changeset I need to remember what were the latest files changed and view their history.

Is there a better way to do this?

riQQ
  • 9,878
  • 7
  • 49
  • 66
boyan
  • 1,115
  • 1
  • 8
  • 11
  • Why do you want to know your current changeset? – Ewald Hofman Oct 13 '11 at 03:33
  • 1
    What happens when your workspace is not representative of a changeset? Consider that you have `$/A` mapped, and you've retrieved changeset A, and you have `$/B` mapped, and you've retrieved changeset B. What changeset is your workspace at? – Edward Thomson Oct 13 '11 at 03:57
  • 10
    @Ewald Consider going back in time to find when a bug started happening. This could require doing "Get Specific Version" operations multiple times on your workspace to get to previous changesets which can be very tedious, lenghty and error prone. Being able to tell which precise Changeset is currently on the workspace is extremely useful to avoid any distraction errors and confirm the culprit. I'm glad I found that command today. – Louis Mar 17 '14 at 15:02
  • Welcome to 5+ years later. To answer @EwaldHofman's question, in my scenario, I have made several changes in my workspace and I want to see what has changed on the server since I did my last 'get'. In my case, I don't know what version I last 'got'. – JMD Mar 01 '17 at 23:23

5 Answers5

114

Your answer is on a MSDN blog by Buck Hodges: How to determine the latest changeset in your workspace

from the root (top) of your workspace, in cmd perform:

tf history . /r /noprompt /stopafter:1 /version:W
Jony Adamit
  • 3,178
  • 35
  • 44
kroonwijk
  • 8,340
  • 3
  • 31
  • 52
4

The common answer to use tf.exe history . /r directly does work, but it can be horribly slow. In our case it takes 10-15 seconds. I now use a two stage check, first checking the revision of some arbitrary files (I'm using the files in the root folder).

With powershell:

$tfexepath = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe"
$localpath = "C:\some\tfs\directory"
    
$result = & $tfexepath history $localpath /noprompt /stopafter:1 /version:W 
"$result" -match "\d+" | out-null
$id = $matches[0]

Then search from the root using the /r flag, but limit the search to start from the revision found above:

$result2 = & $tfexepath history $localpath /r /noprompt /stopafter:1 /version:$id~W        
"$result2" -match "\d+" | out-null
$id2 =  $matches[0]

#result:
Write-Host $id2 

For our code base, this brings down the total time from 10-15 to 1.4-1.5 seconds.

As far as I understand there are no drawbacks or limitations, but I suppose it could be slower in a tiny repository. - I'd be glad to know.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
4

Run a Visual Studio CMD (in my case, for VS2015 is called: "Developer Command Promp for VS2015") and then get into your project folder and execute the following command:

tf history . /r /noprompt /stopafter:1 /version:W
xero399
  • 171
  • 6
  • 2
    Thank you! Without that answer, I would still have wondered why the command is not working in the "command window" pane within Visual Studio. – ojdo Feb 22 '19 at 12:44
1

If you want to use PowerShell (see also; equivalent to answer of @kroonwijk):

  1. enable tfs snapin (once, if not already)

    add-pssnapin Microsoft.TeamFoundation.PowerShell

  2. use tfs cmdlet to get current changeset id

    Get-TfsItemHistory <PATH_TO_PROJECT> -Recurse -Stopafter 1 -Version W

fuma
  • 5,067
  • 4
  • 35
  • 39
1

If you really have no idea what version you have you should use one of the other suggested methods. If you are just not sure if you have a specific version or you are uncertain between a few change sets and you prefer working from the VS TFS GUI you can fallow this steps:

  1. Pick the change set you want to be certain about and do a compare: enter image description here
  2. If you have no difference: enter image description here

    or, if the only files that are different are files that you have pending changes in: enter image description here

That means you are up to date with the version in question.

  1. ** If you are not sure if file that has a pending change is actually also not up to date you can check that file version with properties: enter image description here
Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59