Advanced merging on file level

When merging two branches, I usually just start a merge with git merge <target> and resolve everything by git mergetool (which is configured to be kdiff3 in my case). However, sometimes resolving the conflicts can be tough. Especially if the merge is large and there are non-trivial conflicts for which you don’t immediately know the correct solution. In such cases it can be convenient to be able to unwind the process of resolving a conflicted file a bit. You may want to resolve a file partially, which kdiff3 doesn’t allow. Or you may want to edit the files a bit (i.e. ours, theirs and the common ancestor), before starting the merge. This could be to straighten up the formatting to be consistent accross all three file versions, or something else.

Luckily, git allows that. This page and this page are a helpful read when it comes to merging files “manually”. The following python script is created to automate the process of creating the three file version, ours, theirs and common, and do stuff with it. It is intended to be tweakable and to be adjusted to whatever the circumstances require.