How do I rollback a TFS check-in?

62,744

Solution 1

  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

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

Solution 3

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

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 5

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.

Share:
62,744
Jason
Author by

Jason

Xamarin MVP & Consultant, Microsoft MVP, Author, Speaker, Trainer, .NET Developer

Updated on February 07, 2020

Comments

  • Jason
    Jason over 4 years

    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?

  • Richard Berg
    Richard Berg over 14 years
    Nope, rollback from the History UI was only added in TFS 2010.
  • alchemical
    alchemical about 14 years
    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
    alchemical about 14 years
    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)
  • SHODAN
    SHODAN almost 14 years
    Did not work for me. But that must be because some pinhead set up the TFS with silly policies.
  • Robaticus
    Robaticus almost 14 years
    The functionality is added in to TFS 2010 / Visual Studio 2010.
  • EBarr
    EBarr over 13 years
    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.
  • cloggins
    cloggins over 13 years
    This technique worked for me. The workspace suggestion was very good (and is important if you're dealing with a large code base).
  • Robert Jeppesen
    Robert Jeppesen over 13 years
    Unless changes were later made to the same files that you actually want to keep.
  • Ryan Cromwell
    Ryan Cromwell about 13 years
    To be clear this isn't a true rollback. It's getting an older version. Not the same thing.
  • Simon Gillbee
    Simon Gillbee almost 13 years
    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
    Simon Gillbee almost 13 years
    Except that VS2010 (tf) doesn't work against TFS2008 and since TFPT 2010 has no rollback anymore, you are hosed.
  • Dan
    Dan almost 13 years
    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/…
  • joerage
    joerage over 12 years
    Starting with version August 2011 of TFS Power Tools, to rollback, you don't need to use the command line anymore.
  • Chai
    Chai over 11 years
    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?
  • James Mills
    James Mills over 11 years
    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
  • Malachi
    Malachi about 11 years
    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.
  • Sir Crispalot
    Sir Crispalot almost 11 years
    +1 for pointing out the issue with the Get latest version of item on check out setting!
  • Steve
    Steve about 10 years
    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.
  • Kyle Delaney
    Kyle Delaney over 6 years
    Is there a way to do this from Visual Studio directly?