4

I am trying to format my git log output with pretty formats. So far so good, but when using the 50/72 pattern, the wrapped body breaks the format (screenshot below for reference).

Is there a way to keep the format of the first body line on the subsequent lines?

demo

Pretty format I am using:

git log --graph --format=format:" | %C(bold yellow)%D%Creset%n | %Cred%h%Creset | %C(cyan)%an%Creset | %Cgreen%cr%Creset%n | %s%n | %C(dim normal)%b%n"
Michael
  • 8,362
  • 6
  • 61
  • 88
  • [Related question](https://stackoverflow.com/q/22415347/241211), though without the leading pipe characters. – Michael Feb 11 '22 at 22:27

2 Answers2

2

Here's a body format using %w(maxWidth, firstLineIndent, secondLineIndent):

git log --graph \
 --format=format:" \
| %C(bold yellow)%D%Creset%n \
| %Cred%h%Creset | %C(cyan)%an%Creset | %Cgreen%cr%Creset%n \
| %s%n \
| %C(dim normal)%w(,,3)%b%n"

I recommend using simple, normal white for the body color and bold white for %s.

Here's mine, using

git log --graph \
 --pretty=format:"%n \
%C(bold blue)[state] %C(bold yellow)%D%Creset%n \
%C(bold blue)[info.] %Cred%h%Creset | %C(cyan)%an%Creset | %Cgreen%cr%Creset%n \
%C(bold blue)[title] %C(bold white)%s%Creset%n \
%C(bold blue)%n %w(,10,11)%b"

Screenshot showing the format above in use

Michael
  • 8,362
  • 6
  • 61
  • 88
ytyubox
  • 165
  • 1
  • 15
0

I tried to use the %<|(<N>), %>|(<N>) and %>>|(<N>) placeholders to force the correct alignment directly through git log formatting, but it just does not wanna work with the --graph option.

I ended up using %x00 placeholder to insert 0x01 as a separator between my fields and passing the output of git log through column to do proper alignment based on that separator.

I put the final result in a git plugin which prints one line per commit, but the same thing can be applied to your custom formatting like so:

git log --graph \
  --pretty="%x01%n \ 
  | %C(bold yellow)%D%Creset%n \
  | %Cred%h%Creset | %C(cyan)%an%Creset | %Cgreen%cr%Creset%n \
  | %s%n \
  | %C(dim normal)%b%n%x01" \
| column -s $'\001' -t

Regardless of this, you would be much better off just using something like tig for navigating your repository.

Denys Kurochkin
  • 1,360
  • 1
  • 18
  • 34
codentary
  • 993
  • 1
  • 14
  • 33