Skip to contentSkip to conversation

Replicating the default "git log" format with a format string.

DISCUSSION Kannan Goundan 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

For our workflow, author dates aren't very useful. I'm looking for a way to configure Git so that "git log" shows commit dates instead of author dates.
"--pretty=fuller" gets me almost what I want, but I'd like to avoid the
extra two lines if possible.

I tried achieving this by putting a custom format string in ~/.gitconfig:

[format]
pretty = "%C(auto,yellow)commit %C(auto)%H\nAuthor: %an <%ae>\nDate:
%cd\n\n%w(0,4,4)%B"

This works pretty well, but has a few corner cases. When you do "git log --decorate", the default format decorates commits with ref names. I can add "%d" to my format string, but then the ref names show up all the time, even without "--decorate".

The "--walk-reflogs" option presents a similar problem. The %g* placeholders all become empty strings when "--walk-reflogs" isn't present, which is sort of what I want, but it leaves extra blank lines in the output.

Is it possible to exactly replicate the default "git log" format with a format string?

#1 lore raw
Quoted 16 lines · Kannan Goundan

For our workflow, author dates aren't very useful. I'm looking for a way to configure Git so that "git log" shows commit dates instead of author dates.
"--pretty=fuller" gets me almost what I want, but I'd like to avoid the
extra two lines if possible.

I tried achieving this by putting a custom format string in ~/.gitconfig:

[format]
pretty = "%C(auto,yellow)commit %C(auto)%H\nAuthor: %an <%ae>\nDate:
%cd\n\n%w(0,4,4)%B"

This works pretty well, but has a few corner cases. When you do "git log --decorate", the default format decorates commits with ref names. I can add "%d" to my format string, but then the ref names show up all the time, even without "--decorate".

Quoted 6 lines

The "--walk-reflogs" option presents a similar problem. The %g* placeholders all become empty strings when "--walk-reflogs" isn't present, which is sort of what I want, but it leaves extra blank lines in the output.

Is it possible to exactly replicate the default "git log" format with a format string?

Sadly, no, I don't think it is possible with the current format specifiers. It would be nice if it was, though.

-Peff

#2 lore raw
Quoted 8 lines · Jeff King
Quoted 2 lines

Is it possible to exactly replicate the default "git log" format with a format string?

Sadly, no, I don't think it is possible with the current format specifiers. It would be nice if it was, though.

-Peff
--

Isn't this something that might be obtainable using the new ref-filter work being done?

Regards,
Jake

#3 lore raw
Quoted 9 lines · Jacob Keller
Quoted 5 lines · Jeff King
Quoted 2 lines

Is it possible to exactly replicate the default "git log" format with a format string?

Sadly, no, I don't think it is possible with the current format specifiers. It would be nice if it was, though.

Isn't this something that might be obtainable using the new ref-filter work being done?

It moves in the right direction, but it isn't enough. I don't recall the specifics, but I think it has conditional placeholders for things like "if this is non-empty print it". But there are still some problems:

- the ref-filter formatting isn't unified with the commit pretty-printer formatting. So this wouldn't help for a traversal, anyway.

- the decoration thing needs a new placeholder. "%d" means "always show the decoration", but the OP really wants "show the decoration if the user asked for decorations, and empty otherwise".

-Peff