How do I rollback a TFS check-in?

Visual Studio-2008Version ControlTfsRollback

Visual Studio-2008 Problem Overview


I'd like to rollback a change I made recently in TFS. In Subversion, this was pretty straightforward. However, it seems to be an incredible headache in TFS:

Option 1: Get Prior Version
  1. Manually get prior version of each file
  2. Check out for edit
  3. Fail - the checkout (in VS2008) forces me to get the latest version
Option 2: Get TFS Power Tools
  1. Download Team Foundation Power Tools
  2. Issue rollback command from cmd line
  3. Fail - it won't work if there are any other pending changes
Option 3: Manually Undo Changes
  1. manually undo my changes, then commit a new changeset
Question

How do I rollback to a previous changeset in TFS?

Visual Studio-2008 Solutions


Solution 1 - Visual Studio-2008

  1. Download and install Team Foundation Power Tools.
  2. Open up the Visual Studio command prompt
  3. Navigate to the directory on the file system that TFS is mapped to. If you don't do this you'll get an "Unable to determine the workspace" error when you try to roll back
  4. Make sure everything else is checked in or shelved
  5. run tfpt rollback to bring up the interface.
  6. Choose the changesets you want to rollback
  7. Check in the new versions of the files you rolled back

The big disadvantage of the tool is that it will want to refresh everything in your workspace before you can merge. I got around this issue by creating a new workspace just for the rollback which mapped directly to the place in the source tree where the affected files were.

If you need help to figure out which changesets to roll back, I find the code review tool in the free Team Foundation Side Kicks add-in very helpful.

Solution 2 - Visual Studio-2008

Your solution #1 will work:

  1. manually get prior version of each file

  2. check out for edit

  3. Checkin the file and Ignore server changes when prompted.

The reason why it failed for you is because you must have the "Get latest version of item on check out" option turned on. Turn this option off by going to Tools...Options...Source Control...Visual Studio Tema Foundation Server and unchecking "Get latest version of item on check out"

Cheers

Solution 3 - Visual Studio-2008

Rollback has been moved from tfpt.exe to tf.exe, the Team Foundation Version Control Tool.

TF - Team Foundation Version Control Tool, Version 10.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Rolls back the changes in a single or a range of changesets:
tf rollback /changeset:changesetfrom~changesetto [itemspec] [/recursive]
            [/lock:none|checkin|checkout] [/version:versionspec]
            [/keepmergehistory] [/noprompt] [/login:username,[password]]

tf rollback /toversion:versionspec itemspec [/recursive]
            [/lock:none|checkin|checkout] [/version:versionspec]
            [/keepmergehistory] [/noprompt] [/login:username,[password]]

Solution 4 - Visual Studio-2008

Another way to make your option 1 work is to reverse the order of the steps:

  1. Check Out the items
  2. Get Specific Version to the old version
  3. Check in (ignoring the "warning server version is newer" dialog) OR on the conflicts section of the Pending Changes dialog resolve the conflicts by keeping the local version.

This will work even if you have Get Latest On Checkout set.

Solution 5 - Visual Studio-2008

You have two options for rolling back (reverting) a changeset in TFS 2010 Version Control. First option is using the User Interface (if you have the latest version of the TFS 2010 Power Tools installed).

Rollback Changeset in UI for TFS 2010

The other option is using the TFS 2010 version control command-line application:

tf.exe rollback

I have information about both approaches on my blog post available here: http://www.edsquared.com/2010/02/02/Rollback+Or+Undo+A+Changeset+In+TFS+2010+Version+Control.aspx

Solution 6 - Visual Studio-2008

For reference, if you're using TFS 2010, here's the link to Rollback Command (Team Foundation Version Control) manual.

To rollback a particular changeset, go to Visual Studio Command Prompt (2010), navigate to your TFS workspace directory, and type in command:

tf rollback /changeset:C12345

where 12345 is your changeset number. After this, it will show you the log of what it did and you'll have to sort out merge conflicts.

Solution 7 - Visual Studio-2008

Ahh, just found this CodePlex Article on using TFPT.exe (power tool) to rollback a changeset.

Hope this helps you out.

Solution 8 - Visual Studio-2008

Not having a rollback option is actually feature of TFS ;)

To rollback changes:

  1. Check out whatever specific version of changes you want
  2. Edit->Select All->Copy the text in the file
  3. Checkout whatever version of the file is on the server
  4. Paste over the file and check in.

And now all your intermediate changesets before the rollback are saved as well! What a great feature!

Solution 9 - Visual Studio-2008

If you did 1 check-in and you just want to undo it, that has a changeset # associated with it. Do a history on the folder in question to see the bad changeset. Open it up to see the details (all files changed, etc).

I believe that you can restore or undo a changeset from that screen, but my Visual Studio just crashed when I tried to do this. /sigh -- I definitely share your pain.

Where do I downmod TFS on this site?

Solution 10 - Visual Studio-2008

I think that the Team Foundation Power Tools is the way to go. If there are pending changes you can move them to a shelveset then undo or check in all pending changes before running the rollback command. See http://www.codeplex.com/VSTSGuidance/Wiki/View.aspx?title=How%20to%20undo%20a%20check-in&referringTitle=Source%20Control%20Practices%20at%20a%20Glance for more information.

Solution 11 - Visual Studio-2008

Ben Scheirman - the Changeset Details dialog does not have rollback functionality.

Solution 12 - Visual Studio-2008

Another option is TFSPlus. This Visual Studio Addin adds (among others) Get This Version command to the history window. If you have the file checked out it will replace it with that version. If you do a check in afterwards you will effectively do a rollback to that version.

It works on individual files instead of complete changesets, though.

Solution 13 - Visual Studio-2008

Solution 14 - Visual Studio-2008

Get Specific Version

In Version Type drop down select Type as Changeset

Use Changeset ... button to find your Changeset or just type in, if you know this number.

After you have the specific Changeset.

Check Out

Check In

Solution 15 - Visual Studio-2008

None of these solutions quite worked for me Dave Roberts solution was the closest to what I actually got working. I do not have Get latest version of item on check out enabled, however it seems to be a server policy.

My solution to this is to check the file out for edit, get specific version, then when the conflict is detected use the merge tool (and manually merge none of the changes) so that the file is in the condition it was.

I was going to go with compare with the specific version and copy the entire file then just paste it over the top of the old one.

Still there should be an easier way to do this!

Solution 16 - Visual Studio-2008

The solution above is for TFS2008. TFS2010 has built-in rollback feature. see this article for details.

Solution 17 - Visual Studio-2008

Install the latest version of the TFS Power Tools (August 2011), and you can just right-click on a change set and select "Rollback Entire Changeset". It doesn't get much easier than that.

It's available here: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f

It's hinted at under Team Explorer Enhancements on the above page: > New in this release is the ability to [..] easily rollback changes in version control.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJasonView Question on Stackoverflow
Solution 1 - Visual Studio-2008HelephantView Answer on Stackoverflow
Solution 2 - Visual Studio-2008HapperView Answer on Stackoverflow
Solution 3 - Visual Studio-2008Kevin LoView Answer on Stackoverflow
Solution 4 - Visual Studio-2008Dave RobertsView Answer on Stackoverflow
Solution 5 - Visual Studio-2008Ed BlankenshipView Answer on Stackoverflow
Solution 6 - Visual Studio-2008RuslanView Answer on Stackoverflow
Solution 7 - Visual Studio-2008Ben ScheirmanView Answer on Stackoverflow
Solution 8 - Visual Studio-2008CamelBluesView Answer on Stackoverflow
Solution 9 - Visual Studio-2008Ben ScheirmanView Answer on Stackoverflow
Solution 10 - Visual Studio-2008Phillip WellsView Answer on Stackoverflow
Solution 11 - Visual Studio-2008jloView Answer on Stackoverflow
Solution 12 - Visual Studio-2008Damir ArhView Answer on Stackoverflow
Solution 13 - Visual Studio-2008yogeeView Answer on Stackoverflow
Solution 14 - Visual Studio-2008GuruView Answer on Stackoverflow
Solution 15 - Visual Studio-2008PJUKView Answer on Stackoverflow
Solution 16 - Visual Studio-2008StarCubView Answer on Stackoverflow
Solution 17 - Visual Studio-2008Evgeniy BerezovskyView Answer on Stackoverflow