admin管理员组

文章数量:1435859

git log --graph --oneline --all

is quite useful. How can I align the formatted logs to start in the same column though?

For example

git log --graph --oneline --all --format='%C(auto)%<|(15)%h %d %s'

got me quite close, thanks to

%<|( <M> )
make the next placeholder take at least until Mth display column, padding spaces on the right if necessary.

But a hardcoded %<|(15) will not keep working once the graph itself becomes wider than 15 characters!

git log --graph --oneline --all

is quite useful. How can I align the formatted logs to start in the same column though?

For example

git log --graph --oneline --all --format='%C(auto)%<|(15)%h %d %s'

got me quite close, thanks to

%<|( <M> )
make the next placeholder take at least until Mth display column, padding spaces on the right if necessary.

But a hardcoded %<|(15) will not keep working once the graph itself becomes wider than 15 characters!

Share Improve this question edited Nov 15, 2024 at 22:54 j08691 208k32 gold badges269 silver badges280 bronze badges asked Nov 15, 2024 at 22:03 user3310334user3310334
Add a comment  | 

1 Answer 1

Reset to default 3

You're going to need to postprocess the output, column alignment is a two-pass algorithm, that kind of pretty is outside git log's remit.

First cut at it (for portable scripting put #!/bin/bash up front):

git log --graph --oneline --all --color=always \
| sed 's,.*\x1b\[m ,&\t,' | column -ts$'\t'

which passed my smoketests on a couple histories I've got handy.

本文标签: gitAlign information in a column next to graphStack Overflow