share
Stack OverflowHow do I rollback a TFS check-in?
[+93] [17] Jason
[2008-08-28 15:33:04]
[ visual-studio-2008 version-control tfs rollback ]
[ https://stackoverflow.com/questions/32607/how-do-i-rollback-a-tfs-check-in ]

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?

(3) VSS does not have rollback. They do have another feature that happens to be named "rollback" but in TFS terms it's really a Destroy. (a) you can only do it from the tip; it won't work if any additional changes have been checked in subsequent to the one you want to roll back (b) it PERMANENTLY REMOVES the changes from the database - Richard Berg
(2) Oh how I long for the ease of VSS rollback. - Greg
(3) I stumbled upon this issue recently - why the heck is it so difficult to roll back in TFS. Roll-back it's one of the basic functions of source control - JohnIdol
(3) This is way too painful in TFS! - Jon Kragh
(2) Switch to Mercurial! I changed jobs and roped myself into TFS. I have been writing PowerShell scripts to make it seem like Hg from the command line ever since. - Sumo
[+64] [2009-03-12 12:35:08] Helephant
  1. Download and install Team Foundation Power Tools [1].
  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 [2] add-in very helpful.

[1] http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=15836
[2] http://www.attrice.info/cm/tfs/

(1) You can try this way, but be warned, the tools are not well documented, and even if you can get past all the errors, you may or may not be able to really rollback. (I just tried for 2hrs) - alchemical
(2) This technique worked for me. The workspace suggestion was very good (and is important if you're dealing with a large code base). - cloggins
(2) Warning... there is a catch 22 if you are using mismatched versions of TFS and Visual Studio. I am using VS2010 with TFS2008 (a classic case of IT not catching up with dev) and TF.EXE with VS2010 now has rollback... but it doesn't work against TFS2008. And tfpt 2010 has rollback removed, so I can't do it the old way. - Simon Gillbee
(8) the 'rollback' command was moved out of Power Tools for VS2010, so now you just need to type 'tf rollback' : social.msdn.microsoft.com/Forums/en/tfspowertools/thread/… - Dan
(1) Starting with version August 2011 of TFS Power Tools, to rollback, you don't need to use the command line anymore. - joerage
(1) I believe the Power Tools option will be useful if you intend to revert back the entire changes from a particular changeset. Partial reverting back will not work in this case. Is my understanding correct? - Chai
(1) This option only works if your TFS server supports "rollback". Sadly we use TFS 2008 and upgrading is not an option at this time. There appears to be no feasible way of rolling back changesets with TFS Server 2008. --James - James Mills
(1) Tried getting this working for me and it attempted to checkout the entire of the TFS project which consists of over 20GB of files in various branches for features and releases when I was only wanting to work on a particular feature branch. Not acceptable for my use case. - Malachi
1
[+26] [2008-12-05 14:33:19] Happer

Your solution #1 will work: 1. manually get prior version of each file

  1. check out for edit

  2. 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


(3) Just did it this way after struggling 2 hrs w Power Tools and not getting anywhere...wtf is with TFS not supporting this basic functionality... - alchemical
(1) The functionality is added in to TFS 2010 / Visual Studio 2010. - Robaticus
(3) To be clear this isn't a true rollback. It's getting an older version. Not the same thing. - Ryan Cromwell
(1) +1 for pointing out the issue with the Get latest version of item on check out setting! - Sir Crispalot
2
[+19] [2011-03-18 17:43:28] Kevin Lo

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]]

(1) Is there a way to do this from Visual Studio directly? - Kyle Delaney
3
[+15] [2009-09-04 00:36:56] Dave Roberts

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.


(2) Did not work for me. But that must be because some pinhead set up the TFS with silly policies. - SHODAN
4
[+15] [2011-08-19 16:11:20] Ed Blankenship

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 [1] 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 [2] available here: http://www.edsquared.com/2010/02/02/Rollback+Or+Undo+A+Changeset+In+TFS+2010+Version+Control.aspx

[1] http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f
[2] http://www.edsquared.com/2010/02/02/Rollback+Or+Undo+A+Changeset+In+TFS+2010+Version+Control.aspx

5
[+6] [2011-08-04 11:21:22] Ruslan

For reference, if you're using TFS 2010, here's the link to Rollback Command (Team Foundation Version Control) [1] 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.

[1] http://msdn.microsoft.com/en-us/library/dd380776.aspx

6
[+5] [2008-08-29 16:25:03] Ben Scheirman

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

Hope this helps you out.

[1] http://www.codeplex.com/VSTSGuidance/Wiki/View.aspx?title=Use%20Team%20Foundation%20Power%20Tools%20to%20Rollback%20a%20Change&referringTitle=Source%20Control%20Guidelines

7
[+5] [2010-11-12 20:42:22] CamelBlues

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!


(1) At first i thought this was sarcastic, but this solution may actually work for those of us who aren't lucky enough to have been granted rollback permission. - EBarr
(1) Unless changes were later made to the same files that you actually want to keep. - Robert Jeppesen
(1) Crude but this has been the only way I can perform this in TFS. If I do a checkout then retrieve the old version TFS will AutoMerge to the last version whenever I attempt to check it back in. - Steve
8
[+2] [2008-08-28 15:36:39] Ben Scheirman

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?


Nope, rollback from the History UI was only added in TFS 2010. - Richard Berg
9
[+2] [2008-08-28 17:41:23] Phillip Wells

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 [1] for more information.

[1] http://www.codeplex.com/VSTSGuidance/Wiki/View.aspx?title=How%20to%20undo%20a%20check-in&referringTitle=Source%20Control%20Practices%20at%20a%20Glance

10
[+2] [2009-08-12 18:14:45] jlo

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


11
[+2] [2009-12-24 15:04:43] Damir Arh

Another option is TFSPlus [1]. 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.

[1] http://tfsplus.codeplex.com/

12
[+2] [2010-07-22 17:49:33] yogee
13
[+2] [2011-01-14 16:59:51] Guru

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


14
[+1] [2010-11-03 11:33:12] PJUK

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!


Agreed! Please see also: stackoverflow.com/questions/74194459/… (if interested) - JosephDoggie
15
[+1] [2011-07-11 21:26:33] StarCub

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

[1] http://www.edsquared.com/2010/02/02/Rollback+Or+Undo+A+Changeset+In+TFS+2010+Version+Control.aspx

(1) Except that VS2010 (tf) doesn't work against TFS2008 and since TFPT 2010 has no rollback anymore, you are hosed. - Simon Gillbee
16
[+1] [2011-10-19 02:58:08] Evgeniy Berezovsky

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.


17