Using Visual Studio 2012's built-in merge tool with Git

29,040

Solution 1

If you are using Git Source Control Provider with Visual Studio, it looks like this feature was implemented and is available as of version 1.0.0.

Or if you start using Microsoft's tools for git, that will also use the built-in diff tool. From some of the screenshots, it looks like it'll 2-way merge, with the result at the bottom.

Solution 2

This article explains how to do this. I tried this out and it works. In my usage, the diff was opened in any existing instance of Visual Studio, which is what you preferred.

[diff]
    tool = vsdiffmerge
[difftool]
      prompt = false
[difftool "vsdiffmerge"]
      cmd = '"C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/vsdiffmerge.exe"' "$LOCAL" "$REMOTE" //t
      keepbackup = false
      trustexitcode = true
[merge]
      tool = vsdiffmerge
[mergetool]
      prompt = false
[mergetool "vsdiffmerge"]
      cmd = '"C:/Program Files (x86)/Microsoft Visual Studio 11.0/Common7/IDE/vsdiffmerge.exe"' "$REMOTE" "$LOCAL" "$BASE" "$MERGED" //m
      keepbackup = false
      trustexitcode = true

Or use %VSINSTALLDIR% to always reference the version of Visual Studio that matches the commandline you have opened (this only works when the Visual Studio environment has been setup, either by using the Visual Studio Command Prompt shortcut or manually calling vsvars32.bat):

[diff]
    tool = vsdiffmerge
[difftool]
      prompt = false
[difftool "vsdiffmerge"]
      cmd = '"%VSINSTALLDIR%Common7/IDE/vsdiffmerge.exe"' "$LOCAL" "$REMOTE" //t
      keepbackup = false
      trustexitcode = true
[merge]
      tool = vsdiffmerge
[mergetool]
      prompt = false
[mergetool "vsdiffmerge"]
      cmd = '"%VSINSTALLDIR%Common7/IDE/vsdiffmerge.exe"' "$LOCAL" "$REMOTE" "$BASE" "$MERGED" //m
      keepbackup = false
      trustexitcode = true

Solution 3

Te solution marked as answered did not work for me, but this did (I had the vsdiffmerge.exe location in my path - don't know if it had anything to with it):

[diff]
    tool = vsdiffmerge
    guitool = vsdiffmerge
[difftool]
    prompt = true
[difftool "vsdiffmerge"]
    cmd = $LOCAL $REMOTE /t
    keepbackup = false
    trustexistcode = true
    path = C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsDiffMerge.exe
[merge]
    tool = vsdiffmerge
[mergetool]
    prompt = false
[mergetool "vsdiffmerge"]
    cmd = $REMOTE $LOCAL $BASE $MERGED /m
    keepbackup = false
    trustexitcode = true
    path = C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsDiffMerge.exe
Share:
29,040
Adam Drewery
Author by

Adam Drewery

Updated on December 17, 2020

Comments

  • Adam Drewery
    Adam Drewery over 3 years

    So, I don't know if anyone's noticed but the new Merge Tool packaged with VS2012 is sick-o to the max. I've recently moved to Git for my source control and really want to be able to set up VS2012 as my default difftool/mergetool.

    Any suggestions as to how to do this? I'd rather the diff/merge is started in the active VS2012 window and not a new instance if possible.

  • Ken
    Ken over 10 years
    nest your path inside single quotes then inside double quotes will allow you to keep the parentheses. I.E: "'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\vsdiffmerge.exe'"
  • Adam Drewery
    Adam Drewery over 10 years
    This is the best answer by far- only problem is it doesn't seem to work for me! I hit return after the prompt and nothing happens... git asks me if the merge was successful because the file is unchanged...
  • jessehouwing
    jessehouwing over 10 years
    You can also use %VSINSTALLDIR%, that way, from a Visual Studio command prompt, it should always use the right version of Visual Studio...
  • Adam Drewery
    Adam Drewery over 10 years
    The path is correct and I don't get any warnings from git to indicate otherwise, I read something that suggests there may be a bug in vsdiffmerge when used from the command line though. I'll give it a try with that global path and report back!
  • Adam Drewery
    Adam Drewery over 10 years
    Nope- same behaviour. No crashes or errors, just doesn't start the merge!
  • FarFigNewton
    FarFigNewton over 10 years
    @jessehouwing Are you saying that you would have to use git from the Visual Studio command line not bash or CMD?
  • jessehouwing
    jessehouwing over 10 years
    Yes, when using the %VSINSTALLDIR% variable you need to use the visual studio command prompt, or you can call the vsvars32.bat to load them into any other shell as well.
  • FarFigNewton
    FarFigNewton over 10 years
    @jessehouwing Do you use the visual studio command prompt on a daily basis? I open it maybe once every two years.
  • jessehouwing
    jessehouwing over 10 years
    I do. It's usually my default command prompt, since tools like snk, msbuild etc are all in the path variables by default, making life as a .NET developer a lot easier when leaving VS.
  • MichaC
    MichaC about 10 years
    @AdamDrewery I had a problem like yours. In my case it turned out that I had Visual Studio configured to run as an Administrator and I was trying to kick off vsdiffmerge from a non-elevated command-prompt. My guess is vsdiffmerge is kicking off devenv, and it was silently failing when it tried to elevate to Admin. If I start it from an Admin command prompt it works for me.
  • Edward Thomson
    Edward Thomson over 9 years
    Yes it's a three way merge tool. The "three" in three way refers to comparing the three components: the two branch sides compared to the ancestor. The location of where the merge output is drawn in the UI meaningless. But even if that did matter, you can click the three-pane button to have the merge result in the middle.
  • PhilLab
    PhilLab over 9 years
    I am confused by "$LOCAL" and "$REMOTE$, especially since their order is different in difftool and mergetool. Could somebody enlighten me?
  • digaomatias
    digaomatias almost 8 years
    Amazing, it worked!!! I tried with VS2015, which changes the path from version 11.0 to 14.0.
  • Rosdi Kasim
    Rosdi Kasim about 7 years
    For Visual Studio 2017, the vsdiffmerge.exe location is at - C:\Program Files (x86)\Microsoft Visual Studio\2017\<Edition>\Common7\IDE\CommonExtensions\Microsoft‌​\TeamFoundation\Team Explorer\vsDiffMerge.exe