git diff

By default git usually launches vimdiff for diffs and merges, but I would rather prefer kdiff3 gui for merges/diffs. Here are some of my notes about how to set it up.

For a detailed list of options that git diff supports visit this link

git supports various tools for merge and diff, here is a partial list:


You can setup kdiff3 by default as diff tool by executing follow command:

1
git config --global diff.tool kdiff3

for other tools see here: Viewing all git diffs with vimdiff


Following commands setup the kdiff3 as the global default diff and merge tool. (reference https://stackoverflow.com/q/33308482/916549)

1
2
3
4
5
6
7
git config --global --add merge.tool kdiff3
git config --global --add mergetool.kdiff3.path "C:\\inpath\\kdiff3.exe"
git config --global --add mergetool.kdiff3.trustExitCode false

git config --global --add diff.guitool kdiff3
git config --global --add difftool.kdiff3.path "C:\\inpath\\kdiff3.exe"
git config --global --add difftool.kdiff3.trustExitCode false


Alternatively one can modify the config file in repository to use specific tools for a certain repository (reference: https://stackoverflow.com/a/40817348/916549)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[merge]
    tool = kdiff3
[mergetool "kdiff3"]
    path = C:\\inpath\\kdiff3.exe
    trustExitCode = false
[diff]
    guitool = kdiff3
[difftool "kdiff3"]
    path = C:\\inpath\\kdiff3.exe
    trustExitCode = false


One of the things i found a bit annoying was that git always prompts to launch difftool, default behavior. (reference https://stackoverflow.com/q/7897517/916549y)

1
git config --global difftool.prompt false

or tweak the config file for repo:

1
2
[difftool]
  prompt = false


One the things I wanted to do was to diff a file between commits, following command achieves the same effect (reference https://stackoverflow.com/q/11673434/916549)

1
2
3
git difftool HEAD~3 HEAD~2 path/to/file
git difftool HEAD~2 HEAD~1 path/to/file
git difftool HEAD~1 HEAD path/to/file
 
git