Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an external diff tool for Git in Visual Studio 2013?

I've found this post that explains how you can have Visual Studio 2013 use the built-in diff tool when comparing files in Git, but I'm having the opposite problem. Right now when I right-click on a file in the Git Commit Details window and choose Compare With Previous... VS performs the diff in the default Visual Studio 2013 compare tool, but I want it to use an external diff tool, specifically TortoiseMerge.exe. I have it specified in my C:\Users\[My Name]\.gitconfig and it works properly from the GitBash console, but Visual Studio ignores this setting and always uses its built-in tool.

This is what I have in that .gitconfig:

[merge]
    tool = kdiff3
[mergetool "kdiff3"]
    path = c:/Program Files (x86)/KDiff3/kdiff3.exe
[diff]
    guitool = TortoiseMerge
[difftool "TortoiseMerge"]
    path = C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe

I have also checked my local repository's .gitconfig to make sure it wasn't overriding this setting, and it does not specify any diff or difftool settings.

I have also tried similar settings in my .gitconfig like:

[diff]
    guitool = TortoiseMerge
[difftool "TortoiseMerge"]
    cmd = \"C:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe\" /base:"$REMOTE" /local:"$MINE"

but the behavior does not change.

like image 734
deadlydog Avatar asked Apr 12 '14 21:04

deadlydog


2 Answers

Visual Studio uses the diff.tool configuration setting, not the diff.guitool configuration setting.

Try:

[diff]
    tool = TortoiseMerge
like image 121
Edward Thomson Avatar answered Oct 18 '22 00:10

Edward Thomson


I have had the same issue recently in Visual Studio 2012. I will post the solution here as this is the first thread I found when searching.

My .gitconfig file looked like this:

[merge]
    tool = kdiff3
[diff]
    tool = kdiff3
[difftool]
    prompt = true

[difftool "kdiff3"]
    path = "C:/Program Files/KDiff3/kdiff3.exe"
    keepBackup = false
    trustExitCode = true
[mergetool]
    prompt = true

[mergetool "kdiff3"]
    cmd = "C:/Program Files/KDiff3/kdiff3.exe" $BASE $LOCAL $REMOTE -o $MERGED
    keepBackup = false
    trustExitCode = true

[mergetool "vsdiffmerge"]
    cmd = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsdiffmerge.exe" /m $REMOTE $LOCAL $BASE $MERGED
    keepbackup = false
    trustexistcode = true

The problem was the newlines between config sections.

Changing the file to this worked correctly:

[merge]
    tool = kdiff3
[diff]
    tool = kdiff3
[difftool]
    prompt = true
[difftool "kdiff3"]
    path = "C:/Program Files/KDiff3/kdiff3.exe"
    keepBackup = false
    trustExitCode = true
[mergetool]
    prompt = true
[mergetool "kdiff3"]
    cmd = "C:/Program Files/KDiff3/kdiff3.exe" $BASE $LOCAL $REMOTE -o $MERGED
    keepBackup = false
    trustExitCode = true
[mergetool "vsdiffmerge"]
    cmd = "C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/vsdiffmerge.exe" /m $REMOTE $LOCAL $BASE $MERGED
    keepbackup = false
    trustexistcode = true
like image 36
RichB Avatar answered Oct 17 '22 23:10

RichB