Lee Jenkins
Lee Jenkins

Reputation: 2460

How to get all the commits for a merge request in git?

The git show --raw command will show if a commit hash was generated from a merge:

$ git show --raw -m 3d1718
commit 3d1718fb99d52d35700b596bac45caffd1af00dc (from 8923654049aa49c4813fa612e4108271e0361240)
Merge: 8923654 3f1a071
...

In the case where the merge came from a fork into origin/master, parsing the output will reveal which commit hash was the HEAD of origin/master and which commit hash came from the fork. So far, so good.

Once I have the commit hash from the fork, how would I generate a list of hashes for all the commits that are part of that merge? The history might look like this:

H---->J---->W    origin/master
 \         /
  Q-->R-->T      fork

In this case, the git show --raw -m command would be executed on the hash for W, and I can get the hash for T. But how do I get the hashes for Q and R?

Upvotes: 3

Views: 4552

Answers (2)

padawin
padawin

Reputation: 4476

Would:

git log master~..fork --oneline

Suit you?

It logs all the commits in fork but not in master~ (one commit before the merge).

In term of commits, it would be:

git log J..T --oneline

Upvotes: 5

EncryptedWatermelon
EncryptedWatermelon

Reputation: 5598

git log $(git merge-base --octopus $(git log -1 --merges --pretty=format:%P)).. --boundary
Show commits involved in a prior git merge

Upvotes: -1

Related Questions