2

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?

Lee Jenkins
  • 2,299
  • 3
  • 24
  • 39
  • 1
    Side note (not relevant to your question but it explains a lot about Git :-) ): the internal arrows that Git maintains all point *backwards*, from W to J and T, for instance, and from T to R, and so on. Git works backwards. Any time you find yourself wondering: *why did Git do **that**?*, remember: *oh yeah... Git works backwards* :-) – torek Apr 11 '19 at 20:16
  • I'm voting to close this as duplicate of [How to see commits that were merged in to a merge commit?](https://stackoverflow.com/questions/6191138/how-to-see-commits-that-were-merged-in-to-a-merge-commit) – mkrieger1 Apr 22 '22 at 11:54

2 Answers2

2

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
EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
padawin
  • 4,230
  • 15
  • 19
-1

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

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28