2

Consider the following history:

         c-----f-----i-----l-----o-----p--- branch2
        /           /                   \
       /   e---h---k---n--- branch1      \
      /   /                               \
-a---b---d---g---j---m---------------------q---r--- master

The commit h (branch1) introduced certain changes to a piece of code. At some point in history after h, branch1 was merged into branch2. After a few more commits, branch2 was merged into master.

I want to find the merge commit that introduced the changes made in commit h to master branch (here merge commit q)? I have the commit hash for h.

I tried the solutions given here: Find merge commit which include a specific commit , but they point to the first merge commit after the commit h which is i.

Vivek
  • 2,665
  • 1
  • 18
  • 20
  • @Quentin, Looks Vivek already tried the answers on the question which you mentioned. – Ganesa Vijayakumar Nov 27 '19 at 10:50
  • @GanesaVijayakumar oh god, how have I brainfarted *this* bad? Retracting my VTC, thanks for pointing that out... – Quentin Nov 27 '19 at 10:51
  • 1
    Aside from things like `git log -S` (for which you'd have to use `-m` as well), you can also use graph ancestry tests (`git merge-base --is-ancestor`) on each of the legs of a merge. In this case there's a single unique merge `q` that makes `h` an ancestor of `q` and `p` but not of `m`, so `git log --merges` (or `git rev-list --merges`) to find merges followed by said merge-base testing would get you there. – torek Nov 27 '19 at 22:28
  • 1
    In a more complex graph, however, there may be multiple ways to trace from `r` back to `h`. In this case, you might want the equivalent of `git merge-base`'s "best" commit. That's more complicated to test for, and in particularly nasty DAGs, there may not even be a single best such merge. – torek Nov 27 '19 at 22:30
  • Seems like there is no out of the box solution for this. For the particular graph that I posted, @torek 's solution from his first comment worked, thanks!! However, like he mentioned in his second comment, my actual graph is much more complex and I was not able to get to where I wanted. – Vivek Nov 29 '19 at 17:32

0 Answers0