threads / discuss / 63695

How to exclude tagged commits from git log <revision-range>?

Subject: How to exclude tagged commits from git log <revision-range>?

## tl;dr

3 messages between Jun 25, 2025 and Jun 25, 2025.

replies: 2people: 3as markdown or json

M Hickford· Jun 25, 2025, 20:30 UTC · lore
Hi. Is it possible to exclude tagged commits from a revision range?
I tried
     git log --exclude=ref/tags/v* v2.3.0..v2.4.0
but this didn't exclude any commits.
An inelegant workaround is:
     git log --oneline --decorate v2.3.0..v2.4.0 | grep --invert-match "tag: v"
Junio C Hamano· Jun 25, 2025, 20:47 UTC · re: M Hickford · lore

Re: How to exclude tagged commits from git log <revision-range>?

M Hickford <mirth.hickford@gmail.com> writes:
> Hi. Is it possible to exclude tagged commits from a revision range?

A so called "revision range" is a set of commits that are defined by reachability from two sets of commits, one "positive set" and one "negative set". A commit is in the "revision range" if and only if it is reachable from one or more commits in the positive set but it is not reachable from any commit in the negative set.

> I tried
>
>      git log --exclude=ref/tags/v* v2.3.0..v2.4.0

"--exclude" only affects the selection of "positive set" commits via globbing operators like "--all". When you say "git log --all", the tips of all refs are thrown into the "positive set", but with the --exclude=<glob>, the refs that match <glob> pattern are not thrown into the "positive set". As you have no "--all" or "--glob", it has no effect. Your "positive set" consists of the commit tagged as v2.4.0 and your "negative set" has the commit tagged as v2.3.0.

As "revision range" is a set operation (i.e. compute "the set of all commits that are reachable from any commits in the negative set", and "the set of all commits that are reachable from any commits in the positive set", and subtract the former from the latter), skipping arbitrary commit in the middle, like this one wants to do:

>      git log --oneline --decorate v2.3.0..v2.4.0 | grep --invert-match "tag: v"

would generally be impossible to do. If you want to omit, say, v2.3.5, that is reachable from v2.4.0, and can reach v2.3.0, but cannot be reached from v2.3.0, "excluding" it by throwing it into the "negative set" would also omit anything reachable from it.

Jacob Keller· Jun 25, 2025, 21:26 UTC · re: M Hickford · lore

Re: How to exclude tagged commits from git log <revision-range>?

On 6/25/2025 1:30 PM, M Hickford wrote:
Show 12 quoted lines
> Hi. Is it possible to exclude tagged commits from a revision range?
> 
> I tried
> 
>      git log --exclude=ref/tags/v* v2.3.0..v2.4.0
> 
> but this didn't exclude any commits.
> 
> An inelegant workaround is:
> 
>      git log --oneline --decorate v2.3.0..v2.4.0 | grep --invert-match "tag: v"
> 

What is your actual end goal with this git log? Why do you want to not see tag commits?

I think your "inelegant" solution may be the only way to get what you want.

← back to recent threads