How to use kdiff3 as a difftool / mergetool with cygwin git

First, install kdiff3 for windows.

Second, create the following script somewhere (such as ~/, and change the location of your kdiff3.exe to an appropriate cygwin-style path to where you executable really is). The script is based on Pete Goodliffe’s one he used for svn. I’ve expanded on the idea to make it more flexible. See my next post for a more general version that can be used for any windows program

for arg
if [[ "" != "$arg" ]] && [[ -e $arg ]];
OUT=`cygpath -wa $arg`
if [[ $arg == -* ]];
/cygdrive/d/Program\ Files\ \(x86\)/KDiff3/kdiff3.exe $RESULT

Finally, configure your ~/.gitconfig to:

tool = kdiff3
tool = kdiff3
[mergetool "kdiff3"]
path = ~/
keepBackup = false
trustExitCode = false

No thanks to wordpress for ruining the whitespace formatting… :(

Try running git difftool (make sure you have some modified files) to make sure it works.

About these ads

3 thoughts on “How to use kdiff3 as a difftool / mergetool with cygwin git

  1. If your path contains spaces, this script doesn’t work
    Add single quotes around it and it’s all better :)
    OUT=\’`cygpath -wa $arg`\’

    Otherwise, thanks for the help!

  2. Struggled with this for some time. Didn’t work at all. Finally realized that the must be saved in UNIX format. Thanks for the very general solution!
    in the .gitconfig file for me the path to kdiff3.exe needed to be absolute and not begin with ~.
    Also, just for general information, the specific solution when doing “git difftool” is this:

    /cygdrive/d/mypgms/KDiff3/kdiff3.exe “$1″ “$2″ “$3″ “$4″ “$5″ `cygpath -wa $6` `cygpath -wa $7`
    A containing just this line works too for “git difftool”.

    This expands to:
    /cygdrive/d/mypgms/KDiff3/kdiff3.exe –auto –L1 “alias1 (A)” –L2 “alias2 (B)” win_abs_path_to_A win_abs_path_to_B

    Thanks again,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s