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
It does not work; it just opens 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?
Solution 1:
An additional way to do that (from the 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.
Solution 2:
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
Now, you will be able to run "git difftool" and use your tool of choice.
Specifying your own difftool, on the other hand, takes a little bit more work, see How do I view 'git diff' output with my preferred diff tool/ viewer?
Solution 3:
Others have done a 99% answer on this, but there is one step left out. (My answer will be coming from OS X 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
.