I want to find all the merge commits which affect or involve a given file.
For background, someone mis-resolved a conflict when merging, and it wasn't noticed by the team for a few days. At that point, a lot of other unrelated merges had been committed (some of us have been preferring to not use rebase, or things would be simpler). I need to locate the "bad" merge commit, so it can be checked to identify what else might have been reverted (and, of course, to identify and punish the guilty).
The scenario is like this:
$ echo First > a.txt && git add a.txt && git commit -m 'First commit'
$ git branch branch1
$ echo "Second: main-branch" >> a.txt && git commit -a -m 'Commit on master'
$ git tag a1
$ echo "Third: main" >> a.txt && git commit -a -m 'Other commit on master'
$ git checkout branch1
$ echo "Second: on branch1" >> a.txt && git commit -a -m 'Commit on branch'
$ git tag b1
...So now there are conflicting changes to a.txt in master and branch1.
$ git checkout master
$ git merge branch1
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
Automatic merge failed; fix conflicts and then commit the result.
$ cat a.txt
First
<<<<<<< HEAD:a.txt
Second: main-branch
Third: main
=======
Second: on branch1
>>>>>>> branch1:a.txt
$ vi a.txt
# ...
$ cat a.txt
First
Second: on branch1
$ git add a.txt
$ git commit -m 'Merge commit'
...In other words, the resolution is "take theirs". The graph now looks like this:
$ git log --graph --branches --format='%h %s %d'
* fefb623 Merge commit (refs/heads/master)
|\
| * 93e065e Commit on branch (refs/tags/b1, refs/heads/branch1)
* | cf4d12b Other commit on master
* | 6fade67 Commit on master (refs/tags/a1)
|/
* 07545ea First commit
At this point wrong version of a.txt is on master. The version in a1 is what we want, but the b1 version was committed. So far I've tried:
$ git log --decorate --oneline a.txt
93e065e (refs/tags/b1, refs/heads/branch1) Commit on branch
07545ea First commit
Ok, so neither a1 nor the merge commit appear.
$ git log --decorate --oneline --follow a.txt
...
This shows me everything on both branches, but still omits the merge commits.
$ git log --oneline --graph --decorate a1..master
...
This is of course "everything in master not in a1", which works in this toy example but in my real case gives me all the merges done recently (and no indication of which one touched a.txt).
I can rationalize the disappearance of a1 from the file's history, since the merge chose to omit that change (at least in the sense that git cares about, I think). But how do I locate all the merge commits affecting a.txt? Is this even possible without manually inspecting all the candiate merge commits?