How to rollback in Visual Studio TFS? - visual-studio

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?

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.

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:
In Source Control Explorer, select an item, open its shortcut menu, and choose Rollback.
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.

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

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.

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.

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
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.
Under Type, click Changeset.
Under Changeset, click the ellipses (…).
In the Find Changesets dialog box, either use the default values or
specify criteria for your search, and
then click Find.
Under Results, click the changeset that contains the version to which you
want to revert the file, and then
click OK.
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.
In Source Control Explorer, right-click the file, and then click
Check Out for Edit.
In the Check Out dialog box, click Check Out.
In Source Control Explorer, right-click the file again, and then
click Check In Pending Changes.
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.
In the message box, click OK. The Pending Changes – Conflicts window
appears.
(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
In the Pending Changes window, click Keep Local Version.
In Source Control Explorer, right-click the file, and then click
Check In Pending Changes.
In the Check In - Source Files dialog box, click Check in.

In Visual Studio 2013 this became an easier task. To Rollback, do the following:
In Source Control Explorer, select the solution/project
Right-click, then select "View History"
In the history view, select the changeset you want to roll back
Right-click, then select View changeset details. This opens up the Team Explorer.
In the Team Explorer, click "Rollback":
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.

Related

Visual Studio Team Explorer only checkin some files

We're upgrading from Visual Studio 2010 to 2015. When I use Team Explorer to checkin files, on VS 2010, I could select a directory and it showed all the checked out files in that directory with a checkbox so I could unselect certain files I don't want to checkin. But the checkboxes seem to be gone in 2015, so I have to checkin everything in the directory. Is there a workaround to bring back the checkbox?
(Note I am not asking for a .gitignore to never check in certain files. I do want to check in the files, just not yet. Right now I want to checkin only some of them).
Right click the file in the Pending Changes view and choose "Exclude".
The feature of "Check Box" is gone in VS2015. For now, there are only Included Changes and Excluded Changes.
According to your description, you just need to click and select those files(use ctrl or shift to multiple select) and right click "Exclude"
After the operation, those files will add in Exclude list. You will not check in them. Once you want to check in them again, you just need to included them back to include list.

Visual Studio 2013: auto-refresh solution explorer in "show all files" mode

Is there any way or some unobvious workaround to make the Solution Explorer refresh automatically (in Show All Files mode) when there are changes to the project directory tree? Currently if I rebuild a project with different output settings (which would add some files and remove some others), no changes would get reflected in Solution Explorer until I manually click refresh button. Doesn't seem too convenient for a tool aimed at programming, i.e. automating repetitive tasks...
Update
A picture is worth a thousand words:
My relevant options # Tools > Options > Environment > Documents:
Let's assume that Release directory is empty and Show All Files mode enabled
Now, I build my Release config... Build succeeds, but no changes are visible in Solution Explorer:
Only after I hit refresh button manually can I see the results of build process:
So I'm basically asking if there are ways to make Solution Explorer update automatically when changes occur, not to make externally modified files auto-reload in VS editors.
#Sunny Moon - There is no option right now to automatically refresh the project tree if changes are introduced. You have to manually select the Refresh button in the command bar of Solution Explorer. I'm going to track this feedback along with other areas I've been collecting for Solution Explorer so thanks for sharing your frustration here.
Thanks!
Cathy
Visual Studio IDE Team
Just set check the “Auto-load changes, if saved” check box on VS2013 Option menu >> Environment menu.
That was impossible in VS 2013 and 2015, but with 2017 Microsoft did the right thing and revamped the Solution Explorer a bit - now there is clear and logical separation between solution (virtual) and folder (physical) views, and changes to the filesystem are now tracked and displayed automatically.

Visual Studio 2010 source control disappearing from Solution Explorer

Symptoms
When I open a certain WPF solution in Visual Studio 2010, after the solution loads and is displayed in Solution Explorer, for a moment, I see the source control icons (locks, checkout checks, etc) next to the items in the solution and then they disappear, except for check marks for checked out files. Right clicking any of the items without an icon shows a context menu without any of the source control actions. The checked items can be checked in and then the source control actions disappear for them too. If I open the Change Source Control dialog, the solution and all of the projects have the red line under them indicating they are invalid.
I can unbind each of them, then rebind them to the exact same Server Name and Server Binding successfully. This causes solution explorer to temporarily become source control-enabled again. But if I click the refresh button on solution explorer, I get a dialog stating:
An error occurred while accessing the source control system. Do you want to disable source control for this session.
This causes the solution explorer to lose source control interoperability again.
Yesterday, I tried to download the latest of a different solution that I had update on another machine. I found that somehow the new files I had added to the solution on the other machine were not in TFS. So I excluded them from the project and re-included them to add them to TFS. Then on my machine did Get Latest again. The solution updated so it knew the files should be included but it didn't download the files themselves. I tired Get Latest with Replace files even if the local version matches the server version and they still didn't download. I had to specifically get each file from Source Control Explorer. This may be unrelated but I wanted to include it in case it's not.
What I've Tried
To try to solve the first problem, I reset all VS settings and restarted. This didn't work so I shut it down. I uninstalled TFS Power Tools and that didn't work either. I replaced my .sln and .vssscc with the latest from TFS. I unselected TFS as the source control plug-in and reselected it. Uninstalled the NuGet Package Manager extensions, which also did not help. I don't have any add-ins and the only extensions I have installed now are a few Telerik control extensions, which are not new.
Why are the source control bindings becoming invalid?
Delete the .vssscc file and let Visuasl Studio recreate it when it reloads the project solution.
Try file » source control » change source control . Unbind and rebind .

How can you see the difference between two files in Visual Web Developer 2010?

I've seen some SVN tools that use a "diff" command that will highlight the differences between two files. However, I don't understand how to do this within Visual Web developer 2010 (Express). Any help discovering this method will be greatly appreciated.
Thank you,
PS: I include visual-studio-2010 in the tags as I think it is the closest thing to web developer 2010.
I am not sure if VWD has its own file compare function, but you could use WinDiff from the Windows SDK. Here is the link for version 7.1 - http://www.microsoft.com/en-us/download/details.aspx?id=8279
Taken from http://msdn.microsoft.com/en-us/library/bb385990.aspx
To compare two files
On the View menu, click Other Windows, and then click Source Control Explorer.
In Source Control Explorer, right-click the version of the file that you want to
compare, and then click Compare.
NoteNote
As an option, you can right-click a file in Solution Explorer and then click Compare.
The Compare dialog box appears and the local path of the file that you selected is
in the Source Path box.
Enter the Target Path or click Browse and locate the target folder.
Under Target Version, select the Type you want to use for comparison: Changeset,
Date, Label, Latest Version, or Workspace Version.
Click OK.
If the files have no differences, the Microsoft Visual Studio dialog box appears,
informing you that the files are identical. Click OK.
Otherwise, a difference window displays the files side by side.
I use devart's code compare tool and it worked really good for me. You can download it from here.
http://www.devart.com/codecompare/

How to have TFS 2010 detect changes done to files outside of Visual Studio?

I'm using Team Foundation Server 2010 with Visual Studio 2010.
Whenever I modify a file outside of Visual Studio, TFS doesn't seem to detect the change done to the file, and thus doesn't offer me the option to check-in the file after it has been modified.
How can this be solved?
TFS has a "Reconcile" command for this:
Open the Source Control Explorer
Right-click on the folder with the changes and choose Compare
Select the files you want to reconcile (press CTRL+A to select all files)
Click on the Reconcile button
Set the options in the Reconcile Folder Differences dialog. Make sure Files that do not have pending changes is set to Check Out
Click OK
If you have local changes the Check Out dialog will be shown. Set the preferred Lock type
Click Check Out
See also: Reconcile differences between folders
If you have a network connection to your server while you're working outside of Visual Studio, it's probably best to go ahead and check the file out before editing it, either using the tf command line client, or using the Windows Explorer shell integration that's available in the TFS Power Tools release. (Plus an increasing number of other tools have TFS integration that makes this automatic, but if you're just using notepad, this still needs to be a manual step.)
Of course, there are many times when you're working and you don't have a network connection available that allows you to check out the files.
If you know what files you've modified, you can just check them out from within Visual Studio, then you'll be able to check them back in.
If you don't know what files you've edited, you can detect the changes by running the tfpt online command (also part of the Power Tools release). This will locate the files that have been modified locally and check these files out from the server.
This worked for me, using the TFS Power Tools:
tfpt online /adds /deletes /diff /noprompt /recursive directory-name
(where directory-name is the path to the directory to be updated, otherwise it will detect changes throughout your entire TFS repository)
If you want to know what it would do without it actually making any changes, you can force it to do a dry run by adding the /preview switch.
*1- make changes outside of Visual Studio
2- go to Visual Studio and open Source Control Explorer
3- right click on the folder > "Check Out for Edit" > "Check Out"
4- right click on the same folder > "Undo Pending Changes..." > "Undo changes" > "No to All"*
I tested this workaround on a branch and it helped me a lot. But there are only new files and new folder who has to be done manually.
I recommend to create a branch before the operation. It isolates you the time of the operation.
Note: This technique does also the files identical cleanup that TFS always marks as modified.
Try this. It's some sort of workaround, but it works:
make changes outside of Visual Studio
go to Visual Studio and open Source Control Explorer
right click on the folder > "Check Out for Edit" > "Check Out"
right click on the same folder > "Undo Pending Changes..." > "Undo changes" > "No to All"
That's it. The changes are visible now.
There's also another solution to get TFS to figure out the files that have changed outside of Visual Studio:
Open the solution offline
In Solution Explorer select the solution file and then press the Go Online button ()
TFS will automatically scan the solution for changes after this.
Step one can be achieved in a number of different ways. Here are some:
Use the GoOffline Extension - very simple and effective.
If you're asked for TFS credentials when opening the solution (no automatic domain auth), then don't enter the credentials. The solution will open offline and you'll login after pressing the Go Online button
(extreme solution) Disconnect your network cable; Open the solution; Connect the network cable.
Visual Sourcesafe works like this too and the way I get VSS or TFS to notice the change is by checking the file out once inside Visual Studio.
Open Source Control and go to your TFS folder. Right-click on the folder and choose 'Compare'.
Notice that your edited files show up marked in red.
I find this is better than tfpt online which also gets you files that are not readonly and not edited.
I had this problem in the past, when my Internet was down and I worked offline, and most of my changes didn't appears in Team Explorer.
Following these steps:
First, In the solution explorer, select the folder that you want to re-conciliate (for me, it was my entire solution folder), and select Compare...
Click in Modify Filter, and in the filter text-box, you could type:
*.cs;!obj\;!bin\;!packages\;
In this example, it will include in the search only C# files and exclude in the folders: bin, obj and packages.
Notice the column Pending Change has the info whether the file is marked as edit, add, etc... or nothing...
To mark as edit (when the local item has a matching server item), select the file and choose Check out for Edit...
To mark as add (when the local item doesn't have any server item), select the file and choose Add Files
Finally, I am not sure why the projects are not listed here (after I remove *.cs filter, still doesn't show up), so rebuild the solution to make sure the projects updates as well
+ In the solution, click the connect button (if shows up) that said Go Online.
I found that in Visual Studio 2015, with the project open, Visual Studio discovered for itself that files had been modified externally, and automatically checked them out without me having to do anything. Checking in the project in the normal way saved the external modifications.
In my case, the following worked (at least the one time I tried it):
Go to the Pending Changes panel
Select View Options under either Included or Excluded changes.
Switch between Show All and Show Solution Changes
Switch back if desired
Changing the View Option appears to force a refresh of modified files.

Resources