30
votes

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.

4
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
possible duplicate of git merge using the vs2012 diff tool Not an exact duplicate, but may be worth combining the questions.Roman
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. blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/…allen
@allen Just wanted to add this: 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
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

4 Answers

77
votes

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
13
votes

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.

1
votes

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
0
votes

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