In earlier articles, I described a way to diagram a conflicting merge, and presented an algorithm for efficiently mapping the conflict frontier which is implemented in an experimental program, git-mergemate. In this article, I would like to present a few examples of real-world merge diagrams.
To generate these diagrams, I first used the following command to search for merge commits in "master" that had manually-resolved conflicts:
git rev-list --merges --grep='Conflicts:' master
Assuming that the SHA1 of the merge is stored in $s, the two parents of such a commit can be written as $s^1 and $s^2. So I then ran git-mergemate like so:
git-mergemate diagram $s^1...$s^2
and converted the output from PPM format to PNG using the pnm2png utility .
Show me the pixels!
Each pixel in these diagrams represents one pairwise merge. Thus the images are quite compact; the width (in pixels) is the number of commits on "master" after the branch point, and the height is the number of commits on the branch. I am leaving the images at 1:1 scaling so that their relative sizes can easily be seen (hopefully you can zoom them using your browser if you want to see more detail).
A pixel is green if the corresponding merge was successful and red if the merge resulted in a conflict. The merges that were explicitly tested are shown as bright green/red; the other merges were inferred using the assumptions described in the algorithm article. As you can see, it takes very few test merges to compute a whole merge diagram.
Most of the merge diagrams (about 80% of them) were quite boring.
A typical short branch with a conflict:
A short branch with an early conflict:
A very short branch merged long after it was created:
A longer branch merged soon after it was created, with a conflict with one of its later commits:
However, about 20% of the merge diagrams were more interesting. The interesting diagrams tend to be bigger because they represent long-lived branches merged a considerable time after they were created.
Several diagrams show merges that might be blocked by a single pairwise conflict:
The conflict at the upper-left corner of the red rectangle might be all that is blocking this merge:
A long branch, merged before much was changed on "master":
A short branch, merged quite a while after it was created:
A branch that has diverged widely from "master", but might have only one pairwise conflict:
Other diagrams are yet more complicated, with merge frontiers shaped by two pairwise conflicts:
A smallish diagram with two early conflict blocks:
Note that the top line in this diagram is green, meaning that the first branch commit doesn't conflict with any of the commits on master:
A larger merge with two early conflict blocks:
The biggest merge of all (281 commits on master, 235 commits on branch). Please note that even though the branch and master have diverged significantly, conflicts did not arise until quite some time after the branch was created:
A merge diagram provides a quick, intuitive overview of a conflicting merge, and highlights the individual commits on each branch that conflict with each other.
Most merge diagrams are simple (in fact I didn't observe any with more than two blocking pairwise merges). Thus there is hope that, by focusing our attention on these critical pairwise merges, we can resolve a nightmare merge with an acceptable level of pain and (more importantly) some confidence in the result.
In upcoming articles I will explore how to use incremental merging to resolve a nightmare merge.
Putting this all together, we have
for s in $(git rev-list --grep='Conflicts:' --merges master) do git-mergemate diagram $s^1...$s^2 | pnmtopng >../diagram-$s.png done
If you want to try this with your own git repository, please make a backup first, as the script is only lightly tested!