Aligning git log into columns

Leyan Lo
1 min readMay 31, 2018

--

Fun fact: The column command does not respect ANSI color codes and will flow layout around them as if they were written out, e.g. \033[31m. This of course takes up extra characters, which ruins the columns during output!

git log with misaligned columns 😢

Regex to the rescue! The main culprit in git log --graph are the graph colors. We can target these specifically, by matching any color codes surrounding any of these characters: [|, \, /, _, -, .]. Unfortunately, I wasn’t able to figure out a way of doing this using sed, but was able to pipe the text into perl to get the job done.

git log with aligned columns 😄

Perl command:

perl -pe 's/\x1b\[[0-9;]*m([\|\\\/_\-\.])\x1b\[m/\1/g'

Of course, the proper solution would have been to fix/reimplement column, but that seemed like a lot more work.

--

--