最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

git - Align information in a column next to graph? - Stack Overflow

matteradmin5PV0评论
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.

Post a comment

comment list (0)

  1. No comments so far