Given a commit SHA, how would one find the oldest common ancestor of all parents using plumbing commands? Specifically - of each of the parent branches (one of which is master), select the oldest two (master and X), and then find the point at which they branched.
I've looked through several similar questions like Finding a branch point with Git?, but those didn't seem to deal with potentially having 3+ commits, or use rev-list --first-parent
which I believe doesn't quite get me what I want.
The best I've come up with so far is git merge-base --octopus $(git cat-file -p $(git rev-parse HEAD) | grep parent | awk '{ printf "%s ",$2 }')
, however that gets the 'best' ancestor, not the oldest...
Examples:
a) Given Z, who's parents are L, F, and J, how do I find X?
K ------- L ------- branch_1
/ / \
/ / \
HISTORY-- X -- A -- B -- C -- D -- F --- Z---> master
\ / \ / /
\ / \ / /
G -- H -- I -- J -----/ branch_2
b) Given D, who's parents are C, I, how do I find A?
G --- H -- I branch_1
/ / \
HISTORY--- A -- B -- C -- D ---- master