Geeks With Blogs


View Tarun Arora's profile on LinkedIn

profile for Tarun Arora at Stack Overflow, Q&A for professional and enthusiast programmers

Tarun Arora - Visual Studio ALM MVP ALM, Agile, Automation, Performance Testing, Software QA, Cloud, ...


Oh no! Did you just check in a changeset in to TFS and realized that you need to roll back the changeset because the changes were suppose to go in a different branch? Or did you just accidently merge a wrong changeset in your release branch? There are several ways to undo the damage,

Manual: Yes, we all just hate this word but for the record you could manually rollback the changes.

Get Specific version on the branch and chose the changeset prior to the one you checked in. After that check out all the files in the changeset and check them in. During the check in you will receive a conflict. At this point choose ‘Keep local changes’ in the conflict resolution window and check in the files.

Automated: Yes, we just love it!

TFS comes with a very powerful command line utility ‘tf.exe’ that gives you the ability to rollback the effects of one or more changesets to one or more version-controlled items. This command does not remove the changesets from an item's version history. Instead, this command creates in your workspace a set of pending changes that negate the effects of the changesets that you specify.



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

tf rollback /changeset:ChangesetFrom~ChangesetTo [ItemSpec] [/recursive] [/lock:none|checkin|checkout] [/version:VersionSpec]
[/keepmergehistory] [/noprompt] [/login:username,[password]]


I’ll explain this with an example.

Your workspace is at the location C:\myWorkspace

You want to rollback changeset # 145621

C:\Workspace\MyBranch>tf.exe rollback /changeset:145621 /recursive

How do i rollback/undo a series of changesets?

You can also rollback a range of changesets by using the following

C:\Workspace\MyBranch>tf.exe rollback /changeset:145601~145621 /recursive

This will check out the files in the version control and you should be able to see them in the pending changes. Go on check them in to undo the specific changeset that you just rolled back.

Do you completely want to get rid of the changeset from all future merges between the two branches?


This option has an effect only if one or more of the changesets that you are rolling back include a branch or merge change. Specify this option if you want future merges between the same source and the same target to exclude the changes that you are rolling back.


“If you get the message ‘Unable to determine the workspace.’ You may be able to correct this by running ‘tf worksapces /collection:TeamProjectCollectionUrl’” you are in the wrong directory. Make sure that you run the ‘tf rollback’ command from the directory of your workspace.




Exit Code Description
0 The operation rolled back all items successfully.
1 The operation rolled back at least one item successfully but could not roll back one or more items.
100 The operation could not roll back any items.


To use the command you must have the Read, Check Out, and Check In permissions set to Allow.

So, have you been in a rollback undo situation before?


Share this post :
Digg This
Posted on Monday, June 27, 2011 8:47 PM TFS2010 | Back to top

Comments on this post: How to undo a changeset using tf.exe rollback

comments powered by Disqus

Copyright © Tarun Arora [Microsoft MVP] | Powered by: