Git log pretty format, newline after placeholder if non-empty
Asked Answered
V

1

10

I've got a git alias for a log using the pretty format:

lg = log -10 --graph --abbrev-commit --pretty=format:'%C(auto)%d%Creset%n %C(bold yellow)%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

Which gives the following:

enter image description here

I can't seem to find a way to make a new line after the reference names only if the placeholder is non-empty.

The pretty formats wiki page has operators to add or remove (+ or -) the newline coming before the placeholder but not after.

Vivianviviana answered 16/1, 2016 at 17:13 Comment(1)
Thanks for asking this question. The + operator is what I'm looking for.Langer
A
5

This is not supported natively by Git: you would have to process/parse the output to get the right result)

But this could also be the opportunity for a simple patch, much like the one which originally introduced the Pretty-format: %[+-]x mechanism: commit 9fa708d, git 1.6.6-rc1, Oct. 2009.

Maybe %[*/]x, for adding line-feed after the expansion of %x.

Apposite answered 17/1, 2016 at 10:58 Comment(2)
Thanks, I thought that would be the case. I might have a stab at adding the functionality. I find it strange that nobody has ever added this, seems like a useful thing to have?Vivianviviana
@BenneyBoy444 I agree, it does. It (+-) was added by Juno himself for commit log used for his release notes (ie, to scratch his own itch). Now that you have illustrated another use case, that would justify to extend that feature.Apposite

© 2022 - 2024 — McMap. All rights reserved.