Sunday, May 23, 2010

Rollback Changeset in Team Foundation Server (TFS)

I needed to rollback a changeset in TFS. The changeset had 35 files in it so I really did not want to do each one by hand. I found that with TFS Power Tools it is possible to roll them all back at once, however when I issued the command "tfpt rollback /changeset:14699" I recieved the error "Unable to determine the workspace."

I was thinking that this makes sense as I did not specify the TFS server to connect to so naturally I woundered how to do so. Well after looking through a few search results, I finally found that I simply need to be in a mapped directory in order for this to work.

My project is mapped to D:\MyProject_Root so that is the location which I need to run the command. Below are the steps I took to rollback the changeset.
  1. If you don't have TFS Power Tools installed you may obtain the software from http://msdn.microsoft.com/en-us/vstudio/bb980963.aspx
  2. Start the PowerShell Console (Regular CMD Window may work as well.)
    Start > All Programs > Microsoft Team Foundation Server 2008 Power Tools > PowerShell Console
  3. Change to your mapped directory
    PS C:\Documents and Settings\Developer> d:
    PS D:\> cd myproject_root
  4. Execute the command to rollback the changeset
    PS D:\MyProject_Root> tfpt rollback /changeset:15699
    NOTE: You may get an error if you have any pending changes which have not been checked in. Simply do as the message states.
    "Cannot proceed because you have pending changes in your workspace. You must move to a shelveset, undo, or check in all pending changes before reverting a change set."
  5. You will then be prompted to update your workspace. Click "Yes" to continue.
  6. Prepare to wait for awhile. It seems that it needs to update all mappings from the server. I have three projects on the same server. The two other projects are mapped to folders outside of D:\MyProject_Root but were still updated. So your wait time will depend on the number of projects you have on the TFS server and your connectivity to the server.
  7. Once your wait is over, you will be prompted to select the files in the changeset you wish to rollback. Since I want all of the files rolled back, I left them all checked and clicked the "Roll Back" button.
  8. Your changes will be rolled back. When you open the project you will see these files have been checked out and modified so you will need to modify them or simply check them back in.
I hope you find this useful.