Hidden gem in TFS 2010: How to rollback a changeset with tf rollback

[UPDATE 8/8/11]  The TFS 2010 power tools now provide rollback in the UI as described here.

Tonight Justin and I spoke to the Minnesota Visual Studio User Group.  It was completely unscripted, and we had a great time answering questions and telling a few stories (can you name the original code names for version control, work item tracking and load testing?).  Nearly everyone in the audience was using TFS, and many folks had already moved to TFS 2010.  We covered a lot of ground, touching on parts of VS and ALM – more than just TFS.  I got to thinking as folks were asking questions what might be the one TFS 2010 feature folks in the room probably didn’t know about.  I asked how many folks knew about rollback, and there were just a couple of hands.  I’m pretty sure they were thinking of the rollback command in the tfpt.exe power tool for 2008 and 2005.

We added a full-featured rollback command to tf.exe in Team Foundation Server 2010. You can only use it from the command line, so a lot of folks don’t know about it.  We had plans to add it to the UI (the rollback command was implemented very early in the 2010 development cycle), but higher priority work prevented us from getting to it.

The 2010 rollback command is implemented on the server, handles all of the change types, and it properly rolls back merge history so that it is as if the merge never happened if you roll back a merge (you can control that via a switch if you want a different behavior).

C:\Program Files\Microsoft Visual Studio 10.0\VC>tf rollback /?
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]]

    Date/Time         D”any .Net Framework-supported format”
                      or any of the date formats of the local machine
    Changeset number  Cnnnnnn
    Label             Llabelname
    Latest version    T
    Workspace         Wworkspacename;workspaceowner

So, the next time someone checks in something accidentally (or worse!), you can roll it back easily!  We’ve done this internally a few times.  :-)


Comments (9)

  1. Lavanya says:

    Thanks for the Blog. This is helpful.

  2. Kalim says:

    When do you plan to introduce it into the UI? There is stuff like that is "hidden" and puts many developers off using TFS.



  3. buckh says:

    Kalim, it's in the plans for the next release.  I really hope we get it in there.  As a general rule, we try to have commands avaiable in both the UI and the command line, but we didn't get to it with rollback and baseless merge, which is something we want to fix.


  4. BC says:

    If it's not a complete product, don't release it!

  5. Kishor says:

    Can we roll back a "delete folder"?

  6. buckh says:

    Kishor, yes, you can.


  7. Grant says:

    okay, but how does VS track it? If someone does a rollback, where does VS say to everyone hey, I'm at 1.x.n instead of 1.x.n+5 ?

  8. buckh says:

    Grant, it's stored in the database. Version control keeps track of what files you have in your workspace and what version of each file you have. When a file is rolled back, it creates a new version, which would be 1.x.n+6 in your example. That history of a file is always moving forward.

  9. Keith says:

    I'm a little shocked that this wasn't a standard feature from the start. It's a bit like finding out that your new car has a 'hidden gem' steering wheel that not many owners know about. While all of the other cars have had always steering wheels as standard.

    Even SourceSafe had rollback implemented way back in the 1990s.