Using KDiff3 to edit diffs with Git

Patrick Marchwiak picture Patrick Marchwiak · Sep 25, 2012 · Viewed 7.3k times · Source

Often when I do diffs I want to edit my local file before committing. This works very well in Eclipse's compare view as it allows you to easily edit the local file as well as copy changes from the previous version.

I am trying to set up Git and KDiff3 to work the same way. It works as expected when I'm using KDiff3 as my mergetool. However when I set it up as the difftool, it gives me a read-only view, so I can't do any edits. According to the documentation (http://kdiff3.sourceforge.net/doc/documentation.html), I would expect the --output option to give me the two file merge I want, but it does not. The relevant part of my .gitconfig:

[diff]
  tool = kdiff3
[difftool "kdiff3"]
  cmd = /Applications/kdiff3.app/Contents/MacOS/kdiff3 $LOCAL $REMOTE --output $LOCAL
  trustExitCode = false

Answer

Jacob Helwig picture Jacob Helwig · Oct 20, 2012

I can use KDiff3 to edit the in-tree file if I use the following command:

kdiff3 $LOCAL $REMOTE --output $MERGED

KDiff3 is in my $PATH, so the important bit is to change the output from $LOCAL to instead be $MERGED.

From the git-difftool manpage:

...the configured command line will be invoked with the following variables available: $LOCAL is set to the name of the temporary file containing the contents of the diff pre-image and $REMOTE is set to the name of the temporary file containing the contents of the diff post-image. $MERGED is the name of the file which is being compared.

Since setting the output to $LOCAL is going to write to a temporary file, you'll instead want to write to $MERGED since that will be the actual "local" in-tree file.