3

How can I get git log --graph to print using column unit separators?

I would like the messages to line up vertically, rather than being indented by the graph.

Example command to print the branch graph, author name, and message:

git log --graph --pretty=format:'%an %s' 

The output is indented like this:

 *  Ann  Merge ...
 |\  
 | *  Bob  Merge ..
 | |\  
 | | |  Catherine  Build feature

My goal is a column layout like this:

 *      Ann        Merge ...
 |\  
 | *    Bob        Merge ..
 | |\  
 | | |  Catherine  Build feature

If possible I would like to use column unit separators, such as the ASCII character \031 also known as \x1F.

I'm adding a bounty for any solution that is pure git, i.e. that does not require piping to Unix commands such as column, sed, awk, pr, etc.

joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • 1
    Seems like the pain/gain ratio on duplicating `column`'s functionality in git is maybe a bit high. – jthill May 23 '14 at 02:49

2 Answers2

4

Solution using ASCII x1F as the column unit separator, then piping to the Unix column command available on some distros:

git log --graph --pretty=format:'%x1F%an%x1F%s' | 
column -t -s $'\x1F' |more

(Note that the format string must use single quotes, and the column separator must be preceeded by a dollar sign to trigger the hex character)

joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • another way to circumvent the column thing is using jot :………………………………………………….. column -s$( jot -c 1 12 ) -t – RARE Kpop Manifesto May 11 '22 at 19:06
1

> ... any solution that is pure git, i.e. that does not require piping to Unix commands such as column, sed, awk, pr, etc.

That would be against the unix philosophy of "make each program do one thing well". The column, cut and pr to some extent are the tools for the job (followed by awk), as you've already decided in your answer.

However, just to bring this to the public attention, git does in fact have column-width controlling characters, so you can do,

git log --oneline --pretty=format:'%<(25,trunc)%an %<(100,trunc)%s %<(25)%ad'

to get pure column formatting. The formatting however will be "over-ruled" by the --graph option where necessary, as alas, the graph tracers and separators are not treated as a column in themselves.

mockinterface
  • 14,452
  • 5
  • 28
  • 49