Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the oldest common descendant of two commits in git?

Given two (or more) commits, I want to find the oldest merge which joins them. Something like the opposite of git merge-base (which finds the youngest common ancestors). Notice that the commit I’m looking for will be a younger descendant of the starting commits.

In other words: I want to investigate the merge commit which merged two given commits (where changes to the same file happened).

like image 696
Robert Siemer Avatar asked Nov 21 '22 05:11

Robert Siemer


1 Answers

oldest-merge() { 
        ( for c; do git log --all --merges --ancestry-path ^$c --pretty='%aI %h %s'; done ) \
        | sort | uniq -c | awk "\$1 == $# {print;exit}"
}

oldest-merge `git rev-list --all --grep=BUG-27182`  # e.g. 

the final awk takes the first commit that showed up in all the merge-ancestry lists.

like image 171
jthill Avatar answered Dec 09 '22 13:12

jthill