5

Consider

$ git merge-base <original-branch> <new-branch>

Question: is git merge-base commutative? That is, does the above command yield the same result as

$ git merge-base <new-branch> <original-branch>
Kristján
  • 18,165
  • 5
  • 50
  • 62
George
  • 6,927
  • 4
  • 34
  • 67

1 Answers1

4

If there is only one merge-base, then yes.
Meaning: git merge-base --all <original-branch> <new-branch> returns only one commit.

But, as mentioned in the git merge-base man page:

When the history involves criss-cross merges, there can be more than one best common ancestor for two commits.
For example, with this topology:

---1---o---A
\ /
 X
/ \
---2---o---o---B

both 1 and 2 are merge-bases of A and B. Neither one is better than the other (both are best merge bases).
When the --all option is not given, it is unspecified which best one is output.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    In short, `git merge-base` may happen to be commutative, but the spec of that command offers no such guarantee. – jub0bs Aug 18 '15 at 16:39