3

In keeping with a number of solutions posted on the internet I have installed KDiff3 and modified .gitconfig as below to make use of it. Nonetheless, when I run git diff HEAD^ HEAD within a repository to test it I get a diff performed by the default tool. I'm running cygwin git on Windows7-64. Can anyone explain why KDiff3 is not invoked?

[diff]
    tool = kdiff3
[merge]
    tool = kdiff3

[difftool "kdiff3"]
    path = \"D:/Program Files (x86)/KDiff3/kdiff3.exe\"
    keepBackup = false
    trustExitCode = false

[mergetool "kdiff3"]
    path = \"D:/Program Files (x86)/KDiff3/kdiff3.exe\"
    keepBackup = false
    trustExitCode = false
Abdusalam Ben Haj
  • 5,343
  • 5
  • 31
  • 45
lovelyzoo
  • 55
  • 1
  • 5
  • Where are the various pieces running? Is this all (I hope!) in Cygwin? Are parts native windows applications and if so, which? – AlG Feb 26 '13 at 20:12
  • Yes, its running in cygwin, see jturney's response for where I've got to. – lovelyzoo Feb 28 '13 at 11:33

3 Answers3

3

Actually, the wrapper script is not needed. If kdiff3.exe is not in your path, you need to give the full path in cmd as cmd = /cygdrive/c/apps/KDiff3/kdiff3 ...

My .gitconfit

[diff]
    tool = kdiff3
[merge]
    tool = kdiff3
[difftool "kdiff3"]
    cmd = kdiff3 \"$(cygpath -wla $LOCAL)\" \"$(cygpath -wla $REMOTE)\"
    trustExitCode = false
[mergetool "kdiff3"]
    cmd = kdiff3 \"$(cygpath -wla $BASE)\" \"$(cygpath -wla $LOCAL)\" \"$(cygpath -wla $REMOTE)\" -o \"$(cygpath -wla $MERGED)\"
    keepBackup = false
    trustExitCode = false
[mergetool]
    prompt = false
[difftool]
    prompt = false
E.L.
  • 171
  • 2
  • 3
2

Use git difftool to invoke the configured diff tool, not git diff.

Since you seem to be using cygwin git, but a native kdiff3, you'll probably also need to invoke a wrapper script, rather than kdiff3 directly, to use cygpath convert paths from cygwin form to native form.

jturney
  • 2,510
  • 1
  • 17
  • 24
  • ... [and Google quickly finds an example of such a script](http://noamlewis.wordpress.com/2011/03/22/how-to-use-kdiff3-as-a-difftool-mergetool-with-cygwin-git/) – jturney Feb 26 '13 at 20:23
  • Doing so results in: Viewing: 'file.py' Launch 'kdiff3' [Y/n]: Y After which the tool doesn't launch, I take it the wrapper will resolve this? – lovelyzoo Feb 26 '13 at 20:44
  • Using the windows form of the path to kdiff3 seems unlikely to work. Have you _tried_ using the wrapper script? – jturney Feb 27 '13 at 12:07
  • 1
    OK, I've tried this with the wrapper script. I still get the Launch 'kdiff3' prompt. I respond with Y. Once I do so the response is: "The diff tool kdiff3 is not available as '~/bin/kdiff3.sh'". Note that calling ~/bin/kdiff3.sh successfully starts Kdiff when called on the command line. – lovelyzoo Feb 28 '13 at 11:18
  • 1
    Hmm.. it seems that page isn't quite right, [you can't put ~ in a .gitconfig file](http://stackoverflow.com/a/11262153/1951600), so replace that with /home/jon or whatever your $HOME directory is. – jturney Feb 28 '13 at 12:40
  • I made two significant changes to the linked kdiff3.sh script. First to handle embedded spaces in file name: `OUT="'!cygpath -wa \"$arg\"!'"` (backticks written as `!` here...). And secondly avoid making kdiff3 complain when looking at an added/removed file: `if [[ "$arg" = "/dev/null" ]]; then arg="/cygdrive/c/some_zero_byte_file"; fi` right in front of the `OUT=...` line. – hlovdal May 02 '14 at 11:37
  • Adding home directory instead of ~ did not work for me. Am I missing something ? [mergetool "kdiff3"] path = /home/stadikon/kdiff3.sh keepBackup = false trustExitCode = false – TechCrunch Nov 11 '14 at 18:32
1
git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
git config --global mergetool.kdiff3.keepbackup=false
git config --global mergetool.kdiff3.trustexitcode=false

please check config : git config --global -l

this work fine on cywin 64bit

vuhung3990
  • 6,353
  • 1
  • 45
  • 44