Search code examples
gitbug-trackingblame

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


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.


Solution

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