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

4 messages from 2015-11-12 to 2015-11-13. Participants: Kannan Goundan, Jeff King, Jacob Keller.
Thread: https://gitlist.dev/t/40781

## Kannan Goundan, 2015-11-12 00:55

Subject: Replicating the default "git log" format with a format string.
Message-ID: <loom.20151112T011419-749@post.gmane.org>
URL: https://gitlist.dev/e/loom.20151112T011419-749%40post.gmane.org

```
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, 2015-11-13 05:38

Subject: Re: Replicating the default "git log" format with a format string.
Message-ID: <20151113053800.GE29708@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151113053800.GE29708%40sigill.intra.peff.net
In-Reply-To: <loom.20151112T011419-749@post.gmane.org>

```
On Thu, Nov 12, 2015 at 12:55:53AM +0000, Kannan Goundan wrote:

> 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, 2015-11-13 21:41

Subject: Re: Replicating the default "git log" format with a format string.
Message-ID: <CA+P7+xro=nNfzO6Q6-kGe6C=vJp-z_svd229kRZdf5QjQ+Di8g@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2Bxro%3DnNfzO6Q6-kGe6C%3DvJp-z_svd229kRZdf5QjQ%2BDi8g%40mail.gmail.com
In-Reply-To: <20151113053800.GE29708@sigill.intra.peff.net>

```
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.
>
> -Peff
> --

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

Regards,
Jake

```

## Jeff King, 2015-11-13 21:52

Subject: Re: Replicating the default "git log" format with a format string.
Message-ID: <20151113215246.GA14318@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20151113215246.GA14318%40sigill.intra.peff.net
In-Reply-To: <CA+P7+xro=nNfzO6Q6-kGe6C=vJp-z_svd229kRZdf5QjQ+Di8g@mail.gmail.com>

```
On Fri, Nov 13, 2015 at 01:41:23PM -0800, Jacob Keller wrote:

> 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

```
