Given a commit X in the history of the master branch, I'd like to identify the merge where that commit got included into master. In other words, I want to find the maximal i such that X is an ancestor of master~i
, i.e. the i-th ancestor of master along the first-parent chain. (This assumes that merges into master will have the previous master as first parent, which is usually the case afaik.) How can this be done efficiently?
Example
To give an example, suppose I have the following history:
A - B - C - D - E - F - G - H
\ \ / /
I -[J]- K - L - M
\ /
N - O - P
When I want to find out when J
git merged into the master (upper line), I want the command to return F
. Because from H
the first-parent-only history is H - G - F - E - …
and J
is an ancestor of F
but not an ancestor of E
. Just looking for the nearest merge in the range J..H
would be no good enough, since I don't want to find K
or L
. Both of these are not part of the first-parent-only history of H
since L
is the second parent of F
.