handy "git log" options and the nowrap script


I recently settled on two sets of options to “git log” that I greatly prefer over the defaults. The first is:

--pretty=tformat:"%C(yellow)%h%Creset %Cblue%aN%Creset %Cred%d%Creset %s"

This is basically an improved version of --pretty=oneline that gives output that looks like the following:

I won’t go into the details of that format string, the git-log(1) manpage ought to be sufficient to pick it apart. If something seems confusing about it, contact me and I can explain it further. You can put that in your ~/.gitconfig file as format.pretty=tformat:"..." to make git log use that style by default.

That, combined with another cool feature of git makes for the other git-log style that I find myself using often. git log --graph --decorate --abbrev-commit --all --pretty="tformat:.../oneline" is the other cool command. It looks like this:

It provides a pretty good approximation of the commit trees that programs like GitX and gitk show you, only on the command line instead. Obviously the --pretty part above can be whatever you want, although I usually prefer either “oneline” or the custom tformat string mentioned earlier. I also alias it in my .gitconfig to “git graph”, so that I don’t have to type all that in.

Since I work almost exclusively with git-svn repositories where the short subject with a long message style of commit messages isn’t the standard practice, both of these single line formats can be hard to read. Many of the commit subjects from SVN will wrap, even in a fairly wide (230 character) terminal. To work around this problem, especially when viewing graph output, I’ve written a small perl script that will truncate output at the width of the window (or any other specified width). I know that you are thinking “why not just use cut -c1-$COLUMNS?” but that won’t work very well with output that has color escape sequences in it. The program is called “nowrap” and is available here on github.

By comparison, here’s pretty much the same git graph command as before but with wrapping disabled: