Reputation: 48023
I've been having a surprisingly hard time getting git log
to show tags. I thought I'd found the answer here, but I've just discovered that when I do
git log --tags --no-walk | grep a-tag-pattern-I'm-looking-for
it doesn't work.
In fact it looks like the --tags
and --no-walk
options are red herrings for my purposes. Plain
git log
does show tags, but
git log | grep a-tag-pattern-I'm-looking-for
does not.
I think I can see what's going on: when git log
's output is a terminal, it colorizes tag names differently. But when the output is a pipe, it appears that it not only turns off the colorization, it doesn't output the tag annotations at all.
Can anyone suggest a way to get git log
to show tags in its output, even when its output is a pipe?
git version 2.20.1, if it matters.
Upvotes: 2
Views: 122
Reputation: 60487
As an aside that's too long for a comment, git rev-list
is the core command, the "plumbing", underlying basically all the conveniences that accept a list of revisions.
It's not apparent in the v2.20 git log
docs but it, like basically every command that operates on a generated list of commits, uses git rev-list
's machinery to generate that list and takes all its options.
git log --tags=$yourpattern
has (I think and did some quick checks) always worked, Git just expected people to somehow know it would. Like an easter egg or something :-/. Which I did, once you see how it's put together, the convenience commands starting as (often quite obvious and short) scripts for common core command sequences, you learn: this is doing handy things with rev-list, that's doing handy things with read-tree, la la. It was one of those things people just imbibed, it was (and I'm not even sure how) clear to people who learned about Git by following a particular path.
Upvotes: 0
Reputation: 48023
The problem turned out to be related to the --decorate
option. Those tags I wanted to see are listed only with git log --decorate=short
or git log --decorate=full
.
With git log --decorate=auto
, however, they're shown only if the output is going to a terminal, meaning they were suppressed when I piped git log
's output to grep.
Compounding the difficulty is the fact that the help text was inaccurate in some versions, wrongly claiming that the default value for --decorate
was short
. But the more up-to-date documentation says:
If
auto
is specified, then if the output is going to a terminal, the ref names are shown as ifshort
were given, otherwise no ref names are shown. The option--decorate
is short-hand for--decorate=short
. Default to configuration value oflog.decorate
if configured, otherwise,auto
.
So I ran
git config --global --add log.decorate short
to globally set the default for git log --decorate
to short
, and now I can run both
git log
and
git log | grep …
and see tags and other output consistently.
Upvotes: 2