53

I'm working on one sub-module of a large project for which is use VSTS 2008.

I have a need to rollback the module to an earlier version (about 4 check-ins previous). I tried to do this in the Visual Studio UI, and finally realized there is no option to rollback.

After some research, I determined there is a power tools download that purports to support rollback via a command-line tool. However, there appears to be virtually no documentation for it.

Can anyone describe step by step how to rollback to a previous version in VS2008? (Using Power Tools or otherwise).

Bonus question--anyone know if we might get more robust rollback support in VS2010?

Brett Widmeier
  • 1,056
  • 1
  • 13
  • 22
alchemical
  • 13,559
  • 23
  • 83
  • 110
  • 1
    As this question pops up on Google when asking about rollback in TFS, I just wanted to add that this has been made much easier in TFS 2012. See my answer for more information, – René Mar 21 '13 at 08:45

7 Answers7

41

Right-click on the folder in Source Control Explorer. Choose Get Specific Version. Choose the version that you want to get (by changeset, date, label, etc).

EDIT: At this point your local version will be the version that you want. Check out the changed files and then check them back in. This will bring up the merge wizard and it will probably be complaining about how the server has a newer version than you do. Go through the wizard and merge the files the way you want them (one of the options is to discard the server changes, which is what it sounds like you want). At the end of this process, it may tell you that no files were checked in due to the merge process (or something of that nature), just hit OK and then check in again. This should accomplish what you need.

Brett Widmeier
  • 1,056
  • 1
  • 13
  • 22
  • I believe this allows me to see the version I want -- but how do I tell TFS to make the previous version I want the -current- version of the code. – alchemical Feb 16 '10 at 22:43
  • Edited to include more steps. – Brett Widmeier Feb 16 '10 at 23:13
  • 91
    Pretty sad for TFS if this really is the answer. – alchemical Feb 17 '10 at 00:12
  • 2
    It is a pain, there should be a better way. – Brett Widmeier Feb 17 '10 at 18:52
  • 2
    Also this approach does not work at all work when you want to rollback a folder where new files had been added and/or others were deleted. – bitbonk Mar 03 '11 at 07:19
  • 8
    This is horrible. Having to navigate to EACH file and check it out and back in after getting the older version, just to revert the change. So glad we moved to SVN. – CatDadCode Apr 21 '11 at 16:35
  • Article with the same information: http://msdn.microsoft.com/en-us/library/ms194956%28v=VS.90%29.aspx - so yes, this is really the official way to do it. @bitbonk: The article has info on how to deal with restoring/deleting files – Merlyn Morgan-Graham Nov 01 '11 at 20:57
  • 1
    I tried doing this, got the specific version I wanted, checked out my entire team project, then upon trying to check-in, it just said that no changes had been made and the check-out was being undone. Can't believe Microsoft haven't included rollback functionality, it seems like a pretty fundamental thing to leave out! – TabbyCool May 29 '12 at 14:12
  • Worst thing is, the only reason we're in the situation where we need to rollback is because TFS refused to merge our service references, so we had to delete them in our main and development branches just to do a merge. – TabbyCool May 29 '12 at 14:13
  • 6
    There is a much better and faster way to do this now. Look at @Rene answer. Newer TFS and VS you need to do it via Source Control Explorer and its just 2 steps and works straight away, for all the files in the Changeset. Phew! – Piotr Kula Mar 24 '14 at 11:38
36

This has luckily been made much easier in TFS 2012. Now there is a Rollback option from the GUI.

MSDN has more information on how to do it, and what options are available. Here is the text from MSDN on how to rollback to a specific version:

To roll back to a specific version:

  1. In Source Control Explorer, select an item, open its shortcut menu, and choose Rollback.
  2. In the Rollback dialog box, select Rollback to a specific version.

You can of course also rollback entire changesets or a collection of changesets. And you can also easily rollback to a specific point in time if you wish.

Community
  • 1
  • 1
René
  • 9,880
  • 4
  • 43
  • 49
  • 2
    Yea this worked much better than using rollback in the Solution Explorer as I was doing but each time it just reverted back to the most recent TFS files. Your advice worked great and simple! This is the newest and best answer I think. – Piotr Kula Mar 24 '14 at 11:36
  • 1
    How is Rollback different from Get Specific Version? – Kyle Delaney Apr 24 '18 at 20:17
  • 1
    @KyleDelaney "Get Specific Version" just gets that version to your disk without any pending change, but "Rollback" automatically marks all changed files as "edit, rollback" and you can directly check in the rolled back version... – Christoph Fink Apr 27 '20 at 15:00
12

There IS a way but I don't find it pretty.. Open Visual Studio command prompt and ..

C:\Program Files (x86)\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
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
11

The August 2011 TFS Power Tools added full rollback support right into the Visual Studio 2010 UI.

Download link: http://visualstudiogallery.msdn.microsoft.com/c255a1e4-04ba-4f68-8f4e-cd473d6b971f

This function is also included with TFS 2012.

Warren Rumak
  • 3,824
  • 22
  • 30
  • 2
    This works, but I feel like it's not a true rollback. Desired functionality would be to delete all changesets made since the one we're rolling back to. This just adds a new changeset with the content of the rollback one. – matadur Jul 09 '12 at 20:43
  • @matadur, the problem with that approach is that you could end up removing changes that you don't need to -- such as changes in other branches, other solutions, build process templates, and starting with TFS 2012, Code Review Requests/Responses and Feedback Client Request/Responses as well. You could also end up with orphaned link sin Work Items, orphaned references in builds, and local workspaces that are irrecoverably out of sync with the server. (ie. what would happen when a developer checks some pending changes in?) If you want to "roll back" everything, restore a SQL-level backup. – Warren Rumak Aug 09 '12 at 22:04
  • Worked perfect for us, since we had functionality developed and then after another 10 change-sets it was decided to remove that functionality. This allows you to only rollback specific change-sets. Fantastic! – Neville Apr 03 '13 at 01:05
  • @WarrenRumak Isn't that what TFS is supposed to track (I'd imagine it could be done using foreign keys or something). As far as pending changes, maybe a lock field. – samus Nov 16 '17 at 21:20
6

Bonus question--anyone know if we might get more robust rollback support in VS2010?

Yes. Unlike the Power Tools, which is coded directly against the existing 2008 client API, TFS 2010 has a new API for executing rollbacks directly on the server. This makes them far faster and more reliable, while adding functionality that wasn't possible at all in 2008 such as reverting merge history.

Richard Berg
  • 20,629
  • 2
  • 66
  • 86
6

From the MSDN article How to: Roll Back a Changeset (VS2008 although other versions are available)

To revert to an earlier version of a file

  1. In Source Control Explorer, right-click the file that you want to roll back, and then click Get specific version. The Get dialog box appears.
  2. Under Type, click Changeset.
  3. Under Changeset, click the ellipses (…).
  4. In the Find Changesets dialog box, either use the default values or specify criteria for your search, and then click Find.
  5. Under Results, click the changeset that contains the version to which you want to revert the file, and then click OK.
  6. In the Get dialog box, select the Overwrite writable files that are not checked out check box, and then click Get. The earlier version of the file is copied to your local working folder.
  7. In Source Control Explorer, right-click the file, and then click Check Out for Edit.
  8. In the Check Out dialog box, click Check Out.
  9. In Source Control Explorer, right-click the file again, and then click Check In Pending Changes.
  10. In the Check In - Source Files dialog box, click the file, and then click Check in. The Resolve Conflicts dialog box appears, and a message explains that no files have been checked in because the two versions have changes that conflict.
  11. In the message box, click OK. The Pending Changes – Conflicts window appears.
  12. (Optional) In the toolbar of the Pending Changes window, click Compare Local to Server. The server and local copies appear side by side so that you can review your decision before you roll back the changes
  13. In the Pending Changes window, click Keep Local Version.
  14. In Source Control Explorer, right-click the file, and then click Check In Pending Changes.
  15. In the Check In - Source Files dialog box, click Check in.
John MacIntyre
  • 12,910
  • 13
  • 67
  • 106
4

In Visual Studio 2013 this became an easier task. To Rollback, do the following:

  1. In Source Control Explorer, select the solution/project
  2. Right-click, then select "View History"
  3. In the history view, select the changeset you want to roll back
  4. Right-click, then select View changeset details. This opens up the Team Explorer.
  5. In the Team Explorer, click "Rollback":
    Team Explorer
  6. To make the rollback permanent, you need to check in now. Or you can make changes to the rolled back version and then check in.
Matt
  • 25,467
  • 18
  • 120
  • 187