Is it possible to compare two revisions of a file inTFS? - visual-studio-2010

I'm a bit new to TFS. One common operation which is very easy with every other source control I've used is comparing two different revisions. Say you have 3 revisions. Revision 3 is my current local copy. There was some regression introduced with revision 2(or whatever). So, I need to see what was changed from revision 1 to revision 2. I'm not concerned about what was changed in revision 3.
How do I do this in TFS?

If you use the source explorer to 'View history" on a file, you will see a list of the verions in TFS. Then you can select two versions. Then right-click to compare the two versions.

You can right click on the File and click "Compare...".
There you can set the same Server Path (e.g. "$/Project/Main/File.cs") and use the Changeset "Type:" and set a Changeset Id on the Source and Target.

Actually, one of the things I absolutely love about TFS is the flexibility to compare various versions of files (I'll admit, I love the flexibility but the actual compare tool? Not so much).
You'll have to forgive any mistakes, it has been a while since I've used TFS but I still remember the general idea.
In the solution explorer if you right click the file and click compare, you will be presented with compare dialog. From here you select the two files you want to compare. Make sure both of them point to the server version path.
Under the "Source Version:" in the Type: dropdown, select "Changeset" (or "Date" if you feel confident enough). You should see an elipses that allows you to search for the changeset. You will now be able to select your changeset from history (you may need to press a "Find" button or something, I can't remember by heart). Select Your revision 1 (whatever changeset id that is) and "ok" out of the changeset selection.
The "Target Version" frame will be disabled if the Target Path is pointing to a local file (likewise for the "Source Version" and "Source Path"). So make sure your paths are all pointing to the server versions.
Under "Target Version:" in the Type: dropdown, also select "Changeset". Now using the same steps as above, select the revision 2 changeset.
Finally click "Compare" and enjoy!

If you are using Team Explorer inside Visual Studio, you can go to the Source Control Explorer window and select a file, then view history. Choose 2 versions and right-click to compare.

Related

TFS in Visual Studio - How to get server repo to match local repo

Disclosure: Newbie with TFS and couldn't find useful SO answers
A coworker submitted a bunch of changesets to source control -- Can I just get the most recent one to get all of his changes? Or would I need to get each one individually? In other words, do changesets compound?
And more generally, what's the easiest way to ensure my local repo is identical to the server repo (minus the new things I'm working on).
I'm much more familiar with Git if that would help explain this
With your source control set to TFS in VS (Tools > Options...) just right click on your project file in Solution Explorer and select Source Control > Get Latest Version (Recursive). I do it twice just to make sure I get a message saying "up to date".
You can also use Source Control Explorer and get a specific changeset by right clicking the change set and selecting a similar option, and yes, these will get all changes up to the one you clicked.
Edit:
A little confused rereading your title it sounds like you want the server to match local, then your question is about matching your local to the server. So let me address both.
To get the server to match your local this would be most like a "Check in" (or 'push' in Git) this will merge your files into the server. You can perform a check in by clicking the Team Explorer tab and selecting "Pending Changes" then type a description and click "Check In". Where there are conflicts your will be notified and asked how to proceed, but in most cases following best practices this will not be the case.
Then you will want to match your local with the server (basically a 'pull' in Git) by right clicking the project file and selecting 'Get Latest Version (Recursive)'
Hope this helps.

How to compare local file with shelf file

I have shelved my file, test.cpp and continued working on it. Now I would like to see what additional changes I've made to test.cpp since I made my shelf.
Let's say that after I checked out test.cpp, Bob checked into tfs an update to test.cpp.
Let's make some nomenclature to help:
source_version: the original version I checked out and started working from
latest_version: the test.cpp Bob checked into tfs, the latest version after I started working on test.cpp.
shelf_version: the test.cpp in my shelf, a modification of source_version, lacking Bob's addtions (i.e. not merged).
local_version: the test.cpp that I have on my local disk "local_version", that started from source_version, and has addtional work beyond shelf_version.
Using this set of labels my question reworded would be:
How do I compare local_version with shelf_version.
My options:
In Pending Changes pane, I can
Compare with Workspace Version
This is wrong, this compares local_version with source_version
Compare with Latest Version
This is wrong, this compares local_version with latest_version
In 'Shelveset Details' pane view of the my shelf
Compare with Unmodified Version
This is wrong, this appears to be the same as comparing shelf_version with source_version. Which is odd, this function is already handled in the next compare
Compare with Workspace Version
This is wrong, this compares shelf_version with source_version.
Compare with Latest Version
This is wrong, this compares shelf_version with latest_version.
Thanks
It is really irritating that MS hasn't fix this yet. A workaround that I am currently using is an external diff app and doing the following:
Open your external diff app.
Go to your VS environment and go to the Team Explorer pane and bring up your Shelveset Details.
Bring up the context menu on the file you want to compare (right click or menu key).
Select Open. This'll DL the file to your local system as a temporary file.
Bring up the context menu on the window tab right above the file contents which states the filename and select Copy Full Path.
Go back to your external diff app and paste that file path as the first one you wish to diff.
Go back to your VS environment and open your copy of the same file.
Bring up the context menu on the window tab right above the file contents which states the filename and select Copy Full Path.
Go back to your external diff app and paste that file path as the second one you wish to diff.
Now diff the two files.
I know this is a lot of steps to do something that should be a simple (maybe 1 or 2 click) operation.
If you want MS to get off their ass and implement this feature, you might want to vote for this feature here.
I repro all you steps and you correct that you can't compare the shelf_version with the local_version with the VS compare. I use Beyond compare and when the compare start it lists the left and right side. So I changed the left side to point to the local folder and I could see the outcome you are looking for.

How can I see the change log of a directory with TFS?

I'm interested in seeing the latest changes that landed to a solution with TFS (I'm using Visual Studio). However, I can't seem to find the option: using View History on a solution or project brings up the history of the file itself. Am I missing something?
If you right click on folder the containing a solution in the Source Control Explorer window you'll see all changesets. It's obvious but I had to ask for it too. I am using TFS2010/VS2010.
Edit
Here are the steps:
Team/Connect to Team Foundation Server / select Team Project/ in Team Explorer dblclick on Source Control and in Source Control Explore right click folder containing your solution select View History and here you are.
The View History command will list you all the changesets where the file/directory was changed (add/move/content changed, deleted, etc.).
So if you do a View History on a .sln or .csproj file you'll see only the changes that were made inside the file's content, not on the "Visual Studio Item" and its related item.
To sum up, the View History command is only a File System history, there's not a smarter logic out there.
EDIT
The only way to know what changed inside a solution or project is to do a View History on the common denominator (i.e. the directory that contains everything you want to view history). But it'll still be a File System kind of History.
There's not Logical History for Solution and Projects in Visual Studio. For instance you can't know what files where added to a given project your viewing the history from two given versions. Or what projects were added/removed in the solution.
All the pieces are there (because all the changes are stored in the .csproj or .sln), but the feature itself that parses the content and retrieve the logic you want to see doesn't exist. (by the way, it's a great feature and I agree it should be there).
Bottom line: TFS/Visual Studio gives you two history system:
Based on the source control/file system, by displaying changesets.
Based on the source control/file system, by displaying labels.
That's all...
Right click on folder in solution explorer, and choose View History. Then you can see all the Changesets listed that apply to that directory. Then right click a particular changeset and choose Changeset details... to see what changes occurred in that changeset.

How easy is it to roll back a file that has been checked-in in TFS?

I've (apparently) checked-in (added) a file that shouldn't have been added to a branch. I need to revert this, but since then, 20 or so changesets have been added to the repository.
I'm used to working with Subversion, where it's only a few clicks and it's out. How easy is it in TFS?
TFS is a pain to use in general (personal and biased opinion). Here's a how-to article from Microsoft on how to proceed to revert changes back (warning: more than a few clicks away).
As given in that article, the steps to revert to a prior version of (a) file(s) are:
In Source Control Explorer, right-click the file whose changeset you want to roll back, and then click Get specific version on the
context menu.
In the Get dialog box, select the prior version of the file, and then click Get. For more information, see How to: Retrieve
Old Versions of Files from
Changesets.
After this file is in your workspace, right-click the file, and then click Check Out for Edit on the context menu.
Right-click the file again, and then click Check In Pending Changes.
In the Check In - Source Files dialog box, select the file, and then click Check in.
The Resolve Conflicts dialog box appears.
Click Resolve to open the Resolve version conflict dialog box.
Select Discard server changes.
Click OK.
NOTE: To review your decision before discarding the server changes, you can click Compare to view the server and local copies
simultaneously.
In the Resolve Conflicts dialog box, click Close.
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.
As #Darin has posted, you can simply Get the state of the previous version/changeset onto your PC and then check it in as a new version, thus undoing the effect of the check in. This is dead easy and can be done from the GUI, but does involve a fair bit of faffing around.
If you're happy to use the command line, you can also command TFS to rollback the changeset for you. This does all the "work" of the above option, leaving you with a changeset in your pending changes that will undo the checkin's effect, but hopefully with a bit less effort.
If it is added by mistake, you don't want to roll back. Instead, you want to tf destroy (from the command line) that file in each of the branches.
TFS can be a bear to work with if you add a file, delete it, then re-add a new file with the same name. It makes merging much more difficult.

AnkhSvn undo/revert a commit

How do I undo/revert a change I've commited, with AnkhSvn/VS 2010.
(I'm well aware you can't "delete" stuff in the subversion repository).
The issue is simple,
You're working on HEAD(e.g. rev 100). You figure out something is broken. You view the history, and figure out rev 93 might be the issue. You want to revert the change done in rev 93, test, and commit those reverted changes.
While I know how to resort to the command line to "undo" this, How do you do this with AnkSvn from within Visual Studio ?
Go to the history viewer (Right-click solution -> View Solution history), here right-click on a revision (or a selection of revisions), and use the items in the context menu to undo your changes.
I use the following process:
With the solution working on the trunk HEAD and with no local files, right click the Solution, go Subversion -> merge
The Merge Wizard will pop up.
On the first page select 'Merge two different trees'
On the second page you want the 'From' to be the HEAD (Latest Version) and 'To' to be the specific revision to roll back to (93 in OP case) and using the 'From' URL.
On the third page, for text and binary conflicts I have 'prompt me for each' selected. I have depth as 'working copy' and leave 'Ignore ancestry' and 'allow unversioned obstructions' unchecked.
On the final Merge Summary page perform a dry-run first, check to see that the changes look correct. Then run the merge.
Finally, commit the changes to the trunk.
AnkhSVN wasn't working when I did Update to a Specific Version, I kept getting an error message about "please update the out of date items and then retry commit". After some trial and error I figured out how to undo a committed file using the command Revert to this revision.
Say for example you are at revision 4440 and you want to make 4435 the new head. Use Revert to this revision to discard all changes after the selected revision.
How to make a prior committed version the new HEAD revision
NOTE: You may want to revert an entire a solution, but keep a couple changes made in the "un-done" revisions. If that's the case before you revert you could: copy out the newer files to a temporary location, do the revert, then copied them back in to revert everything but keep a few changed at the desired state.
Below is how to undo/revert a committed change with both ANKH and Tortoise.
ANKH
With solution open in Visual Studio, Right click context menu (this can be a Solution, Project, or any specific file) > View History > Select revision > context menu > Revert to this Revision.
ToirtoiseSVN
In file explorer right click on the file or folder (this could even be the top folder if you want to do a mass undo): Show Log to display a list of revisions, select a revision, then select Context Menu → Revert to this revision. Then at the top folder level do Commit, and all of the items will be reverted.

Resources