Search code examples
gitgit-merge

Is there ever a time when only an octopus merge will do?


The octopus merge looks vaguely terrifying. Is it ever the only way to get something done, or is it purely, um, a convenience function?


Solution

  • First, let me make one more assumption: we're not considering the -s ours strategy (which ignores all but one head and therefore invalidates the parenthetical mark below).

    The short answer is "no": the final result of any octopus merge of N heads can be represented by no more than ceil(log2(N)) merges of two heads at a time. (Or, more simply, by N-1 linear merges.) The drawback, of course, is that these are stored as multiple merge commits rather than a single merge commit, so they can be split apart and then they do not represent the entire merge. But in terms of effect, both on merge bases and on source trees, you can always use multiple merges.

    (The opposite is not true: some number M of sequential merges, M > 1, of various heads, cannot always be performed as a single octopus merge of all of those heads. This is because you can resolve merge conflicts in any pairwise merge, but not in octopus merges. If all of those M merges were conflict-free, the octopus merge will succeed.)