Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using KDiff3 to edit diffs with Git

Tags:

git

kdiff3

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
like image 211
Patrick Marchwiak Avatar asked Sep 25 '12 19:09

Patrick Marchwiak


People also ask

How does KDiff3 integrate with Git?

The simple solution: Edit your computer settings and include the directory with kdiff3.exe in %PATH%. Then test if you can invoke it from cmd.exe by its name and then run Git. Show activity on this post.

How do you edit Kdiff?

Much navigation will be done with the scroll bars and the mouse but you can also navigate with the keys. If you click into either window then you can use the cursor buttons left, right, up, down, page up, page down, home, end, ctrl-home, ctrl-end as you would in other programs.

How do I use Git Difftool?

Instead of running one of the known diff tools, git difftool can be customized to run an alternative program by specifying the command line to invoke in a configuration variable difftool. <tool>. cmd . When git difftool is invoked with this tool (either through the -t or --tool option or the diff.


1 Answers

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.

like image 185
Jacob Helwig Avatar answered Oct 23 '22 14:10

Jacob Helwig