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.
Step-By-Step guide using the UI
Step 1: Get the version of the file you want to revert to into your workspace
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
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
Step 3: Check in the change you just made
Your check-in will generate a version conflict:
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.
The conflict is now resolved:
The check-in was aborted due to the conflicts:
Step 4: Check-in again
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
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.