TFS & Visual Studio ALM – by Neno Loje

(formerly Team System, VSTS)

How to revert changes checked into TFS Version Control

January 10th, 2009 · 1 Comment · Team Foundation Server, Team Foundation Version Control, TFS Tips and Tricks


We did some changes to a file and now want to revert to an older version of that same file. In the concrete scenario we added a method called "Multiply" with changeset 8 and want to go back to the version of changeset 7.

History of the file

Step-By-Step guide using the UI

Step 1: Get the version of the file you want to revert to into your workspace

Rightclick > Get specific version

Choose a version

Find Changeset

Note: verify that the file really contains the version you expect and want to revert back to!

Step 2: Check out the file for editing

Check Out for Edit

Select Lock type and confirm check out 

Note: You can freely specify a lock here to make sure none else checks in a new version of the file you are just trying to revert

Newer version exists in source control

Step 3: Check in the change you just made

Check In

Check In Dialog

Your check-in will generate a version conflict:

Resolve Conflicts

This conflict has to appear so that you don’t accidently check in old stuff. You now have to confirm that you really want to override the version that is currently checked in with the older version in your workspace.

Resolve Version Conflict 

The conflict is now resolved:

All conflicts resolved

The check-in was aborted due to the conflicts:

No files checked in 

Step 4: Check-in again


 File history

Note: If you accidently reverted back to an old version you can use the same steps to open a newer version and upload this as the very latest version again.

Total: 20 clicks.

Alternative using the command-line tools (less clicks)

Instead of 20+ clicks you might think about automating these steps using TF.exe – and are down to 5 commands.

tf get MyClass.cs /version:C8
tf checkout MyClass.cs
tf checkin /noprompt /validate
tf resolve /auto:AcceptYours
tf checkin /comment:"Reverting to older version!" /noprompt

Here’s ready to use batch file, which takes two parameters:

  • %1: Name of the file you want to revert.
  • %2: Version of the file, e.g. if changeset number when C7 stands for changeset 7


Revert.bat in action

Although we use command line commands the check in dialog will pop up to allow us to specify check-in comments, notes and associate work items.

 Check In Dialog after Revert.bat



One Comment so far ↓

  • Sjaaky

    This seems pretty awkward. Certainly with renamed files.
    I forgot to uncheck renamed files with a checkin (They get checked by default, very annoying).
    It is especially awkward since my fault needs to be merged in every branch, otherwise future merging gets difficult.

Leave a Comment