Configuring diff tool with .gitconfig

Viewed 268524

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?

10 Answers

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.

If you want to have an option to use multiple diff tools, add an alias to file .gitconfig:

[alias]
    kdiff = difftool --tool kdiff3

Refer to Microsoft's VS Code Tips and Tricks. Just run these commands in your terminal:

git config --global merge.tool code

But firstly you need add the code command to your PATH environment variable.

Enter image description here

Almost all the solutions in the previous answers doesn't work with Git version 2

Mine: Git version = 2.28.0

Solution of the difftool: git config --global diff.tool vimdiff

After it, you can use it without any problems.

In Windows we need to run the git difftool --tool-help command to see the various options like:

    'git difftool --tool=<tool>' may be set to one of the following:
                    vimdiff
                    vimdiff2
                    vimdiff3

    The following tools are valid, but not currently available:
                    araxis
                    bc
                    bc3
                    codecompare
                    deltawalker
                    diffmerge
                    diffuse
                    ecmerge
                    emerge
                    examdiff
                    gvimdiff
                    gvimdiff2
                    gvimdiff3
                    kdiff3
                    kompare
                    meld
                    opendiff
                    p4merge
                    tkdiff
                    winmerge
                    xxdiff

Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.

And we can add any of them (for example, WinMerge) like

git difftool --tool=winmerge

For configuring Notepad++ to see files before committing:

 git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

And using git commit will open the commit information in Notepad++.

Related