Parzh from Ukraine
Parzh from Ukraine

Reputation: 9873

How to get merge commits to master?

TL;DR: How do I find only those merge commits, that merge into a specific branch?


I have roughly this commit history:

        f → g → - - - - k → l → m           [m] ← feature/2
       /               /         \
      /               /           \
     /               /             \
a → b → - - - - - - h → - - - - n → o       [o] ← master
     \             / \         /
      \           /   \       /
       \         /     \     /              [e] ← feature/1
        c → d → e       i → j               [j] ← feature/3

Currently, all commits are in master, and all branches except for master are gone (push -d).

I'm trying to find only those merge commits that are directed towards master; these are h, n, and o. The commit k is not included because it goes from master.

I'm trying this command:

git rev-list a..o --merges

… but it returns all four merge commits, including k.

How do I find only "merge to master" commits? Ideally, this shouldn't involve parsing commit messages, since those can be changed before the merge (at least, in GitHub).

Upvotes: 1

Views: 137

Answers (1)

LeGEC
LeGEC

Reputation: 51870

Try adding the --first-parent option :

git rev-list --first-parent --merges master
# or :
git rev-list --first-parent --merges a..o

If your master branch can only be updated through merge requests, this will actually always work.

Upvotes: 0

Related Questions