Git Log As A Table
February 13, 2018
A few months ago I spent too much time one Saturday morning figuring out an alias for a perfect git log
. I wanted a table layout with even columns. In preparation for this blog post, I turned it into a function.
When used, your git log
will look like so:
(click image for hi-res – it’s the edge rails git log)
Add the following to your .zshrc
, .bashrc
or .bash_profile
:
gt () {
TOTAL_COL=$(tput cols)
HASH_COL_END=20
DATE_COL_END=32
NAME_COL_END=50
REFS_COL_SIZ=20
MESG_COL_END=$(($TOTAL_COL-$REFS_COL_SIZ))
REFS_COL_END=$TOTAL_COL
HASH="%>|($HASH_COL_END,trunc)%Cblue%h"
DATE="%<|($DATE_COL_END,trunc)%C(green)%cr"
NAME="%<|($NAME_COL_END,trunc)%C(bold blue)%an"
MESG="%<|($MESG_COL_END,trunc)%Creset%s"
REFS="%<|($REFS_COL_END,trunc)%C(yellow)%d"
git log --all --graph --pretty=tformat:"$HASH $DATE $NAME $MESG $REFS"
}
Use gt
from the command-line in your favourite git repo to see it in action. gt
stands for git table.
As it’s a function instead of an alias, it should work nicely even when you resize your terminal and run it again.
Enjoy!