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

送分小仙女□ 提交于 2019-12-04 14:13:03

问题


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.


回答1:


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

Try:

[diff]
    tool = TortoiseMerge



回答2:


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


来源:https://stackoverflow.com/questions/23036294/how-to-use-an-external-diff-tool-for-git-in-visual-studio-2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!