8

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).

Robert Siemer
  • 32,405
  • 11
  • 84
  • 94
  • Isn't it what you want? http://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit – smyatkin_max Sep 18 '15 at 10:43
  • @smyatkin_max No, that question has a branch given, where the merge should be on. (I don’t know yet which branch has the oldest merge commit I’m looking for.) – Robert Siemer Sep 18 '15 at 10:59

2 Answers2

1
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.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

If $a and $b are the two commit hashes and they are both contained in master, then say

git rev-list $a..master --ancestry-path >a
git rev-list $b..master --ancestry-path >b

Then use a diff tool to find the last common line of a an b.

user829755
  • 1,489
  • 13
  • 27
  • I've tried this and when using `cmp` for comparison, I do find a common commit. However this is not the "earliest"/"oldest" common commit that has both `a` and `b` commit's changes. It's not even the "latest"/"youngest" commit either. It's somewhere in between. Not entirely sure. – CMCDragonkai Apr 09 '20 at 05:22