1

Goal (X): I'm looking at a particular line in a file in my git checkout. git blame tells me that this line (in its current form) was first committed in commit 1234abcd which was a commit one of my colleagues did locally in his own repo several months ago. At some later time it was merged into our master branch. I want to find that merge commit.

Y0: The best method I've figured out so far is to run

 git blame master~42 path/to/file/in/question | grep ^1234abcd

for various values of 42, and then do binary search to find the oldest direct ancestor of master that contains the code in question. This works in practice (because our master branch follows a strict "no pushes, only PRs" policy) but is cumbersome.

Y1: I think I would be able to find the merge quickly if only I could get git log to show me all commits that

  • are merge commits, and
  • are ancestors of HEAD, and
  • have 1234abcd as an ancestor

Unfortunately, it seems that Git's notation for specifying revision ranges cannot express the third condition. The 1234abcd..HEAD syntax (which intuitively one would expect does this) instead gives me "ancestor of HEAD but not an ancestor of 1234abcd" and therefore displays all kind of other activity that happened to the master branch after my colleague branched off the working branch that was later merged. That semantics is arguably useful when the starting point was a "pinch point" in the commit graph, but not so much to trace the fate of a random working commit.

Question: Is there a way to do Y1? (Short of writing my own program to parse the commit graph and compute the reachability relation, that is). Or is there a better way to achieve X?

(One naive approach is a non-starter: If I knew which name my colleague used for his working branch when he made the change, I could search commit comments to find one that says it merged that particular branch into master. However, past branch names are not recorded anywhere in the repository, and in fact that commit comment is probably the only place this branch name exists at all by now).

hmakholm left over Monica
  • 23,074
  • 3
  • 51
  • 73
  • Relevant? https://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit – Oliver Charlesworth Nov 26 '18 at 23:14
  • 1
    See https://github.com/mhagger/git-when-merged (I think Michael Haggerty already wrote your tool...). – torek Nov 26 '18 at 23:15
  • @OliverCharlesworth: Very relevant, thank you! In fact I'd say its a duplicate (which my attempts to search prior to asking didn't uncover). For the record, the solution I was looking for is the `--ancestry-path` option to `git log`. – hmakholm left over Monica Nov 26 '18 at 23:30

0 Answers0