Using KDiff3 to edit diffs with Git
Asked Answered
S

2

15

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
Spadiceous answered 25/9, 2012 at 19:8 Comment(2)
Did you to escape the '$' in $LOCAL and $REMOTE, or at least put \" around $LOCAL and $REMOTE?Sunless
I tried that and got the same result. Thanks for the suggestion.Spadiceous
V
8

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.

Vories answered 20/10, 2012 at 19:8 Comment(0)
C
0

Here a step by step guide to configure kdiff3 for GIT in Eclipse:

  1. Let git create a config file
  • can be skipped if there is already a .gitconfig file in your userdir.

    Windows users:

    %userprofile% (copy paste in Explorer adress bar)

  • a file named ".gitconfig" needs to exist there

1.1 open a cmd window, execute:

git config --global --edit
  • The config file was created.
  1. Open the config file ".gitconfig" 2.1 add the following lines to register kdiff3 as the diff and merge tool for git (customize the paths to you needs):

    [difftool "kdiff3"]
    path = "C:\Program Files\KDiff3/kdiff3.exe"
    #

    [mergetool "kdiff3"]
    path = "C:\Program Files\KDiff3/kdiff3.exe"
    #trustExitCode = true
    #

Note: This would be the location to register any other supprted mergetool of your liking.

  1. Create a new "Program" "External Tools Configuration" named "git merge" to execute merges from within eclipse! 3.1 Select the following for the parameters:
  • Location:

    C:\Program Files\Git\bin\git.exe

  • Working directory:

    ${git_work_tree}

  • Arguments:

    mergetool --tool=kdiff3

To execute a merge, use the standard eclipse merge and as soon as the workspace shows the conflicted state (red markers on projects visible) you mark a project you wish to merge and start the "external tools configuration" we created in the steps listed above.

The merge will start and the kdiff3 window will pop up. from now just go along your business and only save the files when you are happy with the merge result, as kdiff will deliver a positive merge feedback if you have saved the file.

Curet answered 18/8, 2021 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.