Git setup

log format

$ git config --global log.date auto:human
$ git config --global format.pretty "%C(bold blue)%h%C(reset) - %C(bold green)%ad%C(reset) %C(white)%s%C(reset) %C(dim white)- %an, %cn%C(reset)%C(bold yellow)%d%C(reset)"

Sample:


e5f07b5 - 2 hours ago Remove an unused method - Jon Smith, Jane Doe (HEAD -> master, origin/master, origin/HEAD)

Since git 2.21.0, git supports a “human” pretty format for dates1, so use %ad in place of %ar in the original. %ad respects a date format you pass in by --date - or the log.date format, so we set that config, and rely on it and use the %ad placeholder, instead of prescribing a particular date format with placeholders like %ar (relative dates), %aD (RFC2822 style)), etc.

Additionally, we use auto: so we only use this human format when output isatty(); ibid 1.

This was adapted from https://stackoverflow.com/a/9074343 to show the committer name.

Before using this, I liked the glol format from oh-my-zsh (modified to show committer name):

%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an, %cn>%Creset"

Referencing a commit

Here’s a format useful for quoting/referencing a commit. I keep the above as a default (it gets picked up by git log without any arguments), alongside the below which I can use via git log --format=quote.

git config --global pretty.quote "%C(bold blue)%h%C(reset) (%C(bold green)%ad %cd%C(reset), %C(white)%s%C(reset)%C(dim white); %an, %cn%C(reset))%C(bold yellow)%d%C(reset)"

This is what it looks like:


e5f07b5 (Thu Apr 30 13:21 Thu Apr 30 14:06, Remove an unused method ; Jon Smith, Jane Doe) (HEAD -> master, origin/master, origin/HEAD)

I call it a “quote” format and errs on the side of providing more information, which you can edit away when you are quoting/referencing a commit in, say, a commit message. For example, in the below, I edited out things like the hour/minute of the commit and the author’s name (be kind, let’s not attribute blame to any person(s)!):

Also group products by order for /api/bar

In 7b5e5f0 (Thu Apr 30, Move grouping of products by order closer to its only use), we changed the shape of product expected by calculateAppliedDiscounts() for /api/foo, but missed out another call site through /api/bar.