There are several ways you can find a common ancestor commit for a group of branches. There are several answers in the question Branch length: where does a branch start in Git?.
One answer (it's one of mine) is to use the show-branch
command, passing in as arguments a list of branches that you want to compare and find a common ancestor commit for. Here's an example from the Linux Kernel Git documentation for show-branch
$ git show-branch master fixes mhf
* [master] Add 'git show-branch'.
! [fixes] Introduce "reset type" flag to "git reset"
! [mhf] Allow "+remote:local" refspec to cause --force when fetching.
---
+ [mhf] Allow "+remote:local" refspec to cause --force when fetching.
+ [mhf~1] Use git-octopus when pulling more than one heads.
+ [fixes] Introduce "reset type" flag to "git reset"
+ [mhf~2] "git fetch --force".
+ [mhf~3] Use .git/remote/origin, not .git/branches/origin.
+ [mhf~4] Make "git pull" and "git fetch" default to origin
+ [mhf~5] Infamous 'octopus merge'
+ [mhf~6] Retire git-parse-remote.
+ [mhf~7] Multi-head fetch.
+ [mhf~8] Start adding the $GIT_DIR/remotes/ support.
*++ [master] Add 'git show-branch'.
In that example, master
is being compared with the fixes
and mhf
branches. Think of this output as a table, with each branch getting it's own column, and each commit getting its own row. Branches that contain a commit will have a +
or -
show up in their column in the row for that commit.
At the very bottom of the output, you'll see that all 3 branches share a common ancestor commit, and that it is in fact the head
commit of master
:
*++ [master] Add 'git show-branch'.
This means that both fixes
and mhf
were branched off of that commit in master
.