How do you find who merged a git commit into a branch?
Asked Answered
P

4

12

There is a file in our git repository in work, I want to find out who merged this file into a branch.

I have the commit hash that identifies the commit (lets say 552a976f1a25f9bad57efb9455e951f6b7b3367f) that introduced the file, and I know that the file is on the branch staging.

How can I find the hash of the commit that merged the commit above into the staging branch? I want to find the user who merged, and the date of the merge.

Prevaricator answered 14/5, 2012 at 15:0 Comment(2)
Was it an actual merge (as opposed to a fast-forward merge)? And can't you just use git log path/to/the/file (or gitk)?Studhorse
git log shows the name of the person who committed the file, I want to find who merged that commit onto the staging branch.Khalsa
P
3
git log <commit-id>..<branch> --ancestry-path --merges --reverse

will give you the list of merges that happened since the <commit-id> that you're interested in and the current state of the <branch>. Depending on your merging workflow, the merge you're interested in may be the first one on the list or one of the next ones.

It will be helpful to visualize the relevant part of history with

git log --oneline --graph --decorate --ancestry-path --boundary <commit-id>..<branch>

Look for your <commit-id> near the bottom of the graph (it will belong to "graph boundary" - marked with o rather than *).

Pronuba answered 1/6, 2017 at 11:43 Comment(0)
B
2

branches

If I understand you correctly, you have C5, and you are searching for C6. If it's the case, you are probably looking for this:

git rev-list --merges HEAD --not <hash> --reverse

It will give you the list of merge commits which happened after your hash commit. I use HEAD in this command believing that you are be on master, in the example, or staging in your situation.

In a not-too-complex environment you are probably looking for the first merge which happened after your commit... But if you have not this kind of chance, You can try:

git log --graph --decorate HEAD...<hash>^

Or any graphic tool to explore your history (such as gitk)...

Beckmann answered 15/5, 2012 at 9:54 Comment(0)
A
1
git log -1 --merges <hash>

Will show the most recent merge commit log since the <hash> commit (including itself).

Aphis answered 14/5, 2012 at 15:10 Comment(2)
This is a pretty good solution, sometimes the merge is the first merge, but not always. In my case it was the second merge that was the one I was interested.Khalsa
git log <hash> will show you commits before <hash>, not after (i.e. it will show the ancestors of <hash>). So, this command will show last merge preceding your commit, not the merge that brought it to main branch.Elroy
U
0

Under the condition that all merge commits in your target branch have a commit from the target branch as first parent, which will happen if you use a "standard" git workflow (such as when merging using a CI), then you can use git-when-merged.

Usage:

git-when-merged <commit> <target branch>

The way git-when-merged works is (quoting the documentation): look for the oldest commit on the first-parent history of each BRANCH that contains the COMMIT as an ancestor.

Ureide answered 18/7, 2022 at 8:7 Comment(1)
My understanding is that this will return the first result given by the command in the answer of Jan Warchoł.Ureide

© 2022 - 2024 — McMap. All rights reserved.