Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doing a three-way compare with Git and KDiff3

Tags:

git

kdiff3

diff3

Is it possible to set Git up so that I can use the three-way compare in KDiff3?

I have two branches that are far too different to auto-merge them, I simply have to check each merge point and I think the best way would be to check out the branch I want the changes from the other branch and say

git difftool HEAD_OF_OTHER_BRANCH -- .

And then select Merge File in KDiff3. After having gone through the files I'd just commit.

I have set up merge.conflictstyle and diff.conflictstyle to diff3 but KDiff3 still starts with a two-way diff. Is this possible? I guess if Git also sends the common ancestor's hash as a parameter, this is possible, but does it?

There is discussion about how to do this with SVN and BC3, but I couldn't find anything for Git and KDiff3.

like image 476
Makis Avatar asked Sep 03 '10 12:09

Makis


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.

What is the purpose of KDiff3?

KDiff3 can be used to merge two or three input files and automatically merges as much as possible. The result is presented in an editable window where most conflicts can be solved with a single mouseclick: Select the buttons A/B/C from the button-bar to select the source that should be used.

How does Git compare work?

For Git, that's git diff : you give it the hash ID of the old commit, and the hash ID of the new commit, and it makes a diff for each file that's changed between the two. The output of git diff is a series of instructions: delete these lines, add these other lines.


2 Answers

Run this on the command line:

git config --global mergetool.kdiff3.path /path/for/your/kdiff3/binary  

Then, when solving conflicts you just have to do:

git mergetool --tool=kdiff3
like image 112
Edson Medina Avatar answered Sep 30 '22 06:09

Edson Medina


It seems that git diff do only a 2-way diff (which make sense to generate patch etc) except in a merging state , you have to do a merge for that. I was in a similar situation the other day and I ended up mergin using the ours strategy. That worked but wasn't ideal. Maybe we need a 'nonresolve' merging strategy which doesn't try to resolve any conflicts. You might be able to emulate that by tweaking the .git/MERGE_* files and set all the files as conflicted.
Otherwise the obvious solution is to checkout 3 different directory and run kdiff3 , but I guess you are looking for a more elegant solution

like image 38
mb14 Avatar answered Sep 30 '22 06:09

mb14