Skip to content

Instantly share code, notes, and snippets.

@stebulus
Created April 18, 2020 18:50
Show Gist options
  • Select an option

  • Save stebulus/24bcd0a105b410601af1df0da01f1afe to your computer and use it in GitHub Desktop.

Select an option

Save stebulus/24bcd0a105b410601af1df0da01f1afe to your computer and use it in GitHub Desktop.
$ git log --graph --oneline --decorate --all
* d11c4a4 (HEAD -> prod2) Merge commit 'aa689c2' into prod2
|\
* \ 3f11482 Merge branch 'fnord' into prod2
|\ \
* | | 0e22a4b add b
| | | * 53e966a (prod1) Merge branch 'fnord' into prod1
| | |/|
| | |/
| |/|
| * | 39bf86a (fnord) add fnord
|/ /
| * aa689c2 add a
|/
* c5420c3 (master) initial commit
$ git merge-base prod1 prod2
39bf86ad99e012bdf618365b372bc9c166e22017
$ git rev-parse fnord
39bf86ad99e012bdf618365b372bc9c166e22017
$ git log $(git merge-base prod1 prod2)..prod2
d11c4a48a71b021e9d453a31d94c0633fe9ed833 (HEAD -> prod2) Merge commit 'aa689c2' into prod2
3f11482a284eab953526c35f19794e4d5a2b06e7 Merge branch 'fnord' into prod2
0e22a4b2eca03323de7906ec49234352f3c0fa12 add b
aa689c26010b9d2a9aa00390699321b46480b22e add a
@stebulus

Copy link
Copy Markdown
Author

In this example, branch fnord was merged into prod1 and prod2, and is their merge base. prod1 was also merged into prod2, so prod2 has aa689c2, but fnord does not. Thus git log $(git merge-base prod1 prod2)..prod2 contains commits that we'd think of as being part of prod1, not prod2.

@stebulus

Copy link
Copy Markdown
Author

git log prod1..prod2 gives the desired result (except that it includes merges).

@stebulus

Copy link
Copy Markdown
Author

(So you could do git log --no-merges prod1..prod2 to get what you want.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment