Search code examples
gitgit-log

git - get commits between tags on second level (--second-parent?)


I try to get all commits between two tags.

If the git history is:

* A - 2.0
| \
|  * B
| /
* C
|
D  - 1.0

I can use git log 2.0..1.0 --first-parent to get commit A, C and D.

What would be the git command for:

* X - 2.0
|\
| * A
| |\
| | * B
| |/
| * C
| |
| * D
|/
* Z  - 1.0

To also only getting A, C and D. Everything I tried so far (min/max parents) had included commit B or excluded A, C and D.


Solution

  • If you know for a fact that 2.0 is a merge commit, you can use 2.0^2 to say "the second parent of that merge commit" :

    git log --first-parent 1.0..2.0^2