March 16th, 2011

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

Buck Hodges
Director of Engineering

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

Versionspec:
    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.  🙂

Enjoy!

Author

Buck Hodges
Director of Engineering

Director of Engineering, Azure DevOps

0 comments