Configuring diff tool with .gitconfig?

How do I configure git to use a different tool for diffing with the .gitconfig file. I have this in my .gitconfig:

[diff]
    tool = git-chdiff #also tried /bin/git-chdiff

and it does not work, it just open the regular command line diff. When I do

export GIT_EXTERNAL_DIFF=git-chdiff

then git diff will open up the external diffing tool (so I know the external diff tool script works fine). Do I have something wrong with my .gitconfig configuration for the diff tool?


Git offers a range of difftools pre-configured "out-of-the-box" (kdiff3, kompare, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, diffuse, opendiff, p4merge and araxis), and also allows you to specify your own. To use one of the pre-configured difftools (for example, "vimdiff"), you add the following lines to your ~/.gitconfig :

[diff]
    tool = vimdiff

Specifying your own difftool, on the other hand, takes a little bit more work, see How do I view 'git diff' output with a visual diff program?


Additional way to do that (from command line):

git config --global diff.tool tkdiff
git config --global merge.tool tkdiff
git config --global --add difftool.prompt false

The first two lines will set the difftool and mergetool to tkdiff - change that according to your preferences. The third line disables the annoying prompt so whenever you hit git difftool it will automatically launch the difftool.


Others have done a 99% answer on this but there is one step left out. (My answer will be coming from OSX so you will have to change file paths accordingly)

You make these changes to your ~/.gitconfig :

[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = /Applications/Diffmerge.app/Contents/MacOS/diffmerge $LOCAL $REMOTE

This will fix the diff tool. You can also fix this without editing the ~/.gitconfig directly by entering these commands from the terminal:

git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "/Applications/DiffMerge.appContents/MacOS/diffmerge $LOCAL $REMOTE"

The 1% that everyone else failed to mention is when using this you can't just run git diff myfile.txt you need to run git difftool myfile.txt .

链接地址: http://www.djcxy.com/p/50892.html

上一篇: 如何停止使用@Scheduled注释启动的计划任务?

下一篇: 使用.gitconfig配置diff工具?