25

Using Visual Studio 2015 Update 2 and git as source control, how do you diff between 2 commits on a branch? Note that I am not talking about diff on the granular file level (ie. view history of file and comparing), but rather for entire commits.

I would expect to be able to compare when looking at the history of a branch, but the option does not exist. Here's the right click menu I see when I right click on a commit when viewing the history of a branch:

enter image description here

Where's the compare??

bitbyte
  • 483
  • 1
  • 6
  • 10
  • 1
    Maybe you could use SourceTree, the solution would be more simple. – John Jang Jun 14 '16 at 17:54
  • @John_J that's what I'm forced to do, but it'd be nice to do this in VS – bitbyte Jun 14 '16 at 17:56
  • SourceTree (or other git-specific GUIs) are much better then VS2015's semi-baked implementation of a git client. But even with SourceTree (which I use), I sometimes have to drop to the command line to do things faster (or do something complicated). – tgharold Jun 20 '16 at 19:05
  • Just wasted 20 minutes of my time trying to figure this same thing. Really wish Microsoft would allow us to compare commits in VS2015... – hededo Dec 06 '16 at 17:30

3 Answers3

43

While not possible in Visual Studio 2015, this functionality will be included in Visual Studio 2017.

In Visual Studio 2017 it will be possible to get the changes between two different commits. This functionality can be accessed via selecting two commits on the history page and choosing the "Compare Commits..." command:

Compare Commits entry point

This functionality is present in the preview releases of Visual Studio 2017, so you can try it out and see if it is what you are looking for.

jamill
  • 1,682
  • 13
  • 9
  • 1
    Is it available also for those who don't use Team Services? we use git (not github) and the "History" tab just says "Team Foundation Server is not your current Source Control plug-in. Click here to set the current Source Control plug-ing" (and I click, see that "Git" is selected, click "Ok" and get back to this page with no change...) – Tar Feb 08 '17 at 13:46
  • 2
    Yes - viewing history is available for any local Git repository. If you see that message (Team Foundation Server is not your current Source Control plug-in), this is not the right window - that is the window for viewing TFVC source control. The Git history can be accessed via the branch indicator on the bottom right of Visual Studio in the status, from the "Actions" link of many of the Git related Team Explorer pages, or on the Branches Team Explorer page by right clicking on the branch you want to view the history of. – jamill Feb 08 '17 at 14:40
  • 1
    Thanks! but the "Compare Commits..." is grayed out :-( – Tar Feb 08 '17 at 17:42
  • 4
    You need to select the 2 (and only 2) commits that you want to compare (use ctrl + click). If you are still having trouble getting this to light up, let me know. – jamill Feb 08 '17 at 18:43
  • 1
    You made my life so much better now :-D – Tar Feb 09 '17 at 09:06
1

In Visual Studio 2015, to get a diff with two non-consecutive commits:

  • Make sure the two commits are on different branches
  • Checkout the earlier commit, then right-click on it in Team Explorer and choose "Merge From"
  • Select the later commit to merge from. Make sure the "Commit changes after merging" checkbox is NOT checked then click on Merge
  • All changes will be shown between the two commits in the "Changes" view of Team Explorer. You can Abort the Merge after you're done with the diff if you wish
JohnnyHerms
  • 86
  • 2
  • 12
0

Don't know about VS 2015 update 2. But, in update 3, you can...

1) Right click a commit from history and select View Commit Details from the context menu

2) Right click the file you want to look at and select Compare with Previous from the context menu.

3) View diff window...

(Don't think you can get diff with two non-consecutive commits.)

Tor
  • 778
  • 1
  • 6
  • 9