Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top