threads / discuss / 40781

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

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

## tl;dr

4 messages between Nov 12, 2015 and Nov 13, 2015.

replies: 3people: 3as markdown or json

Kannan Goundan· Nov 12, 2015, 00:55 UTC · lore
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?

Jeff King· Nov 13, 2015, 05:38 UTC · re: Kannan Goundan · lore

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

On Thu, Nov 12, 2015 at 12:55:53AM +0000, Kannan Goundan wrote:
Show 22 quoted lines
> 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?

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

-Peff
Jacob Keller· Nov 13, 2015, 21:41 UTC · re: Jeff King · lore

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

On Thu, Nov 12, 2015 at 9:38 PM, Jeff King <peff@peff.net> wrote:
Show 8 quoted 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

Jeff King· Nov 13, 2015, 21:52 UTC · re: Jacob Keller · lore

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

On Fri, Nov 13, 2015 at 01:41:23PM -0800, Jacob Keller wrote:
Show 9 quoted lines
> On Thu, Nov 12, 2015 at 9:38 PM, Jeff King <peff@peff.net> wrote:
> >> 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

← back to recent threads