Git log excluding branch
Asked Answered
P

1

16

Consider the following commit history:

1---R---3---5---P->                  # patch-v1.1
     \       \
      2---4---+---8---+---10---R->   # release-v2.0
           \         /
            6---7---9                # feature-foo

--> time

# 1 - 10 are commits
# P is a patch release commit
# R are major release commits
# + marks a merge commit

I want to generate the changelog for release-v2.0, but since P (patch-v1.1) has already been released, it's changes should not be part of the v2.0 changelog. Can I configure the git log command to only list commits 2, 4, 6 .. 11 (i.e., commits from release-v2.0 and feature-foo)?

Procto answered 29/2, 2016 at 16:48 Comment(4)
I haven't tested it (yet), but I assume it doesn't, seeing that I sometimes merged patch-v1.1 commits into the release-v2.0 branch.Procto
Oh, didn't notice the patch merge, then what about git log P..R?Ragnar
Does that include 2, 4, 6 and 7 as well? They chronologically happened before P.Procto
You can find more information at git help rev-parse (SPECIFYING RANGES).Ragnar
C
20

Use git log R --not P. That's the same as git log P..R from @micha-wiedenmann's comment, but I find the former syntax more speaking. And yes, it will include 2, 4, 6, 7, 9 as it does not matter when they chronologically happened (in terms of time authored), but where they are in the DAG. With R --not P you basically create the complement of P in R in terms of set theory.

Celestinacelestine answered 29/2, 2016 at 17:33 Comment(1)
So as not to get the merge comments identified as + in the DAG above, you should likely also include the --no-merges option. Merge commits don't usually contribute meaningful information to a changelog.Volnak

© 2022 - 2024 — McMap. All rights reserved.