Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is git merge-base commutative?

Tags:

git

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>
like image 483
George Avatar asked Sep 28 '22 00:09

George


1 Answers

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.

like image 159
VonC Avatar answered Nov 02 '22 03:11

VonC