Git mergetool is a wonderful command. However, I find very annoying that it shows all the diffs with respect to the BASE (possibly hundreds), rather than the conflicts only (often just a couple). This answer (Tip One) provides a solution... which however is manual (take the output of git merge, create three different files with its chunks, compare them). I'm certainly willing to spend half an hour in writing a wrapper for my favourite visual diff editing app which does this automatically. But is there already a way to achieve this?
-
What merge tool do you use? kdiff3 will automatically resolve all differences that are not conflicts (and even some conflicts). Perhaps your tool has a similar option? – asm Oct 08 '13 at 12:48
-
I tried kdiff3, and that feature ("Automatically Solve Simple Conflicts") is indeed very nice - it's lacking in meld, the tool I usually use. Still, kdiff3 is apparently not as good as git, so I'm still left with some more conflicts. Moreover, git does the job anyway, so it's strange that it's impossible to exploit such markers... But that said, thanks for the tip. – Pietro Battiston Nov 18 '13 at 13:49
-
I'm not sure what you mean by `Moreover, git does the job anyway`. If git is resolving merges itself then you should not need to be resolving conflicts with mergetool. – asm Nov 18 '13 at 15:25
-
@AndrewMyers: I think my self-answer clarifies my needs, (sorry for not noticing your comment sooner). – Pietro Battiston Jan 22 '14 at 13:10
1 Answers
Well, I found no ready solution around, so I ended up writing the simple wrapper in question:
http://pietrobattiston.it/mergetooltool
Here's how it works: git tells you it found a conflict in file "conflicted.txt". It leaves markers in it, delimiting the different versions.
You call "/path/to/mergetooltool.py conflicted.txt", it parses "conflicted.txt", recognizes the markers, and simply creates two separate files, one with each version.
Then, it opens your diff GUI (I use meld, you can simply set yours at line 9), lets you resolve conflicts (the version you want to use should be left in the left pane, the one showing "conflicted.txt.local"), and when you close puts the merged version back at "conflicted.txt".
You can then do "git add conflicted.txt" and (if you don't have other conflicted files) "git commit", and you're done.
Why is it better than pure git: well, it depends on taste, but I find diff GUIs handy.
Why is it better than git mergetool: because you will have to solve only the conflicts.
Why is it better than git mergetool with kdiff as a diff tool: because you can use the tool you prefer, and because git is a bit better than kdiff at solving solvable conflicts.

- 7,930
- 3
- 42
- 45
-
Wow. This is an interesting way to get around meld being poor at conflict resolution. It must have a really amazing UI. – Edward Thomson Jan 22 '14 at 15:21
-
Not sure I get what you mean, but kdiff3 too is poorer than git at conflict resolution. – Pietro Battiston Jan 23 '14 at 17:11