My Take on the Git Commit Logger

27 July 2013

I've recently migrated this blog, and the older posts might not yet be
satisfactorily cleaned up. Apologies for the temporary mess.

Almost all the work that I do on my computer that is worth doing goes through a Git repository. My Git commits are therefore a useful indication of what I’ve accomplished each day, except they are scattered across many directories.

When I saw that Brett Terpstra created a script to make a log of all his Git commits, I saw the solution to my problem. Terpstra has an implementation that scans a list of repositories once per day, filters certain kinds of commits, and exports them in different kinds of formats. That’s more power than I needed, so I wrote my own script. The main difference is that where Terpstra’s script is run by cron once per day and goes out to fetch commits, my script is run after every commit and pushes the information to the log.

The script is run using the magic of Git hooks, in this case, post-commit. Any script named post-commit in the .git/hooks directory will be called after each commit.

<span class=“c1”># Write git commit messages to a log file</span>
<span class=“c1”># </span>
<span class=“c1”># Lincoln A. Mullen | lincoln@lincolnmullen.com | http://lincolnmullen.com</span>
<span class=“c1”># MIT License <http://lmullen.mit-license.org/></span>
<span class=“c1”>#</span>
<span class=“c1”># You will have to install the git gem for this to work:</span>
<span class=“c1”># gem install git</span>
<span class=“c1”>#</span>
<span class=“c1”># Name this file 'post-commit' and drop it in the directory '.git/hooks' in</span>
<span class=“c1”># any repository that you want to log. Make sure the file is executable. You</span>
<span class=“c1”># can also add this to your git templates, which will put it in every new</span>
<span class=“c1”># repository or to existing repositories by re-running git init. </span>
<span class=“c1”># </span>
<span class=“c1”># A commit message in the log should look this this:</span>
<span class=“c1”># 2013-07-26-11-25-55 [repository:branch] First line of commit message</span>