4

In Visual Studio lets assume the following scenario:

  1. Create a branch from the master.
  2. Make some changes.
  3. Commit.
  4. Again make some changes.
  5. Commit.

When we make a commit there are no changes displayed under the Team Explorer > Changes. If we didn't do the step 5 the Changes tab will display the current changes compared with the previous commit. I need to know how to compare current state of the branch(committed + uncommitted) with the original code(master branch).

harinsamaranayake
  • 751
  • 2
  • 12
  • 32
  • Do you mean as in https://stackoverflow.com/a/57833947/6309? – VonC Sep 25 '20 at 05:55
  • Does this answer your question? [How to compare different branches in Visual Studio Code](https://stackoverflow.com/questions/42112526/how-to-compare-different-branches-in-visual-studio-code) – dan Apr 21 '21 at 05:53
  • 1
    The links provided are helpful for Visual Studio Code but not for Visual Studio 2019 – J.J Sep 23 '21 at 16:04

2 Answers2

2

If you are using the Microsoft DevOps as your remote repository. DevOps has a way to compare branches. Under the "Repos/Branches" menus.

Example Heading:

Branch compare Comparing "RevampTasks" to "Development"

cc sdk
  • 21
  • 2
2

For Visual Studio 2019 (as asked)

  • Open window Git Changes
  • Click on Additional Operations

Git Changes Window

  • Click Manage Branches

enter image description here

  • Select the two commits/branches you want to compare (with ctrl+click)

enter image description here

  • Right click on one of the selected commits and choose Compare Commits

enter image description here

  • Now at the bottom right you should have a list of the files that have been changed and you can click on them to see the differences between them.

enter image description here

J.J
  • 881
  • 16
  • 29
  • Good answer. When viewing those differences, is there a shortcut key for jumping to the next difference? – jk7 Jun 14 '22 at 21:35
  • I don't remember but with VS2022 yes https://learn.microsoft.com/en-us/visualstudio/version-control/git-browse-repository?view=vs-2022#compare-branches – J.J Jun 16 '22 at 01:33
  • Selecting two branches doesn't appear to be possible. If I right-click a second branch, it deselects the first one. Any suggestions? – Mike Hofer Nov 09 '22 at 18:11
  • Hmmm. @Mike Hofer, I have to control LEFT click to select two branches. I know the post says right click, but that does nothing for me but bring up a pop-up menu. Try ctrl-left-clicking and see if that works for you. – markaaronky Nov 09 '22 at 19:39
  • Nope. No dice. We *are* talking about selecting multiple branches in the Repository window, right? (As shown in the pictures above?) – Mike Hofer Nov 09 '22 at 20:35
  • The answer was specific for VS2019, in VS2022 there is new features, have you checked the link https://learn.microsoft.com/en-us/visualstudio/version-control/git-browse-repository?view=vs-2022#compare-branches ? – J.J Nov 09 '22 at 22:51
  • I don't use VS2019 anymore but the doc says: "Select the two commits/branches you want to compare (with ctrl+click)" then "Right click on one of the selected commits and choose Compare Commits". Maybe the issue is that you are trying to click the branch instead of the commit from the branch? – J.J Nov 10 '22 at 17:22