30

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.

Adam Drewery
  • 1,508
  • 1
  • 17
  • 25
  • AFAIK, The TFS merge tool is a two-way merge tool meaning that it will only expect two files to merge. Git needs a three-way merge tool (the third file being the base ancestor of the other two files). So my current best guess is that it is not possible. – Sardaukar Oct 01 '12 at 12:32
  • possible duplicate of [git merge using the vs2012 diff tool](http://stackoverflow.com/questions/12507396/git-merge-using-the-vs2012-diff-tool) Not an exact duplicate, but may be worth combining the questions. – Roman Oct 01 '12 at 17:10
  • 1
    Have you seen the latest VS integration with Git. If you are working with VS as your IDE this should be pretty handy for you. http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx – allen Jan 31 '13 at 04:11
  • @allen Just wanted to add this: http://blogs.msdn.com/b/bharry/archive/2013/01/30/git-init-vs.aspx . Maybe adding these links as an answer helps highlighting this nice option. – Grimace of Despair Feb 01 '13 at 03:49
  • Installed this and it's everything I could have hoped for! Excellent answer. Can't rate it though as it's added as a comment and not an answer. – Adam Drewery Feb 01 '13 at 09:47

4 Answers4

77

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
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
FarFigNewton
  • 7,108
  • 13
  • 50
  • 77
  • 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'" – Ken Sep 26 '13 at 19:50
  • 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... – Adam Drewery Nov 06 '13 at 16:07
  • You can also use %VSINSTALLDIR%, that way, from a Visual Studio command prompt, it should always use the right version of Visual Studio... – jessehouwing Nov 06 '13 at 22:02
  • 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 Nov 07 '13 at 07:52
  • Nope- same behaviour. No crashes or errors, just doesn't start the merge! – Adam Drewery Nov 07 '13 at 08:16
  • @jessehouwing Are you saying that you would have to use git from the Visual Studio command line not bash or CMD? – FarFigNewton Nov 07 '13 at 16:14
  • 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. – jessehouwing Nov 08 '13 at 08:59
  • 2
    @jessehouwing Do you use the visual studio command prompt on a daily basis? I open it maybe once every two years. – FarFigNewton Nov 08 '13 at 14:20
  • 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. – jessehouwing Nov 08 '13 at 16:05
  • 2
    @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. – MichaC Apr 09 '14 at 21:11
  • 2
    I am confused by "$LOCAL" and "$REMOTE$, especially since their order is different in difftool and mergetool. Could somebody enlighten me? – PhilLab Nov 17 '14 at 08:09
  • Amazing, it worked!!! I tried with VS2015, which changes the path from version 11.0 to 14.0. – digaomatias Aug 15 '16 at 12:51
  • For Visual Studio 2017, the `vsdiffmerge.exe` location is at - `C:\Program Files (x86)\Microsoft Visual Studio\2017\\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsDiffMerge.exe` – Rosdi Kasim Jun 21 '17 at 04:14
13

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.

Roman
  • 19,581
  • 6
  • 68
  • 84
  • 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. – Edward Thomson Oct 16 '14 at 00:11
1

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
Küzdi Máté
  • 661
  • 8
  • 12
0

In Visual Studio 2019 you can easily do this by just going to Tools->Source Control -> Git Global Settings -> Tools Section and then "Use Visual Studio" for Diff Tool, Merge Tool or both

MelOS
  • 595
  • 5
  • 10