Leveraging git for fun and profit

I like writing sample projects to proof the concepts I write about. Usually this involves a git repo where I develop an idea and have branchs which correspond to posts on a particular topic. I recently had an epiphany where I realised that my posts inevitably become extensions of my commit history! This led me to try out a new method of writing which I think is novel: Write the blog post paragraph by paragraph corresponding to my commits (there is no way that there are not lots of other people doing this, but its new to me)! Once I reach a point where I can say, “good enough for a rough draft”, I run the following from my command line:

git log -p --reverse --format='%n%b' master..

Let us disect this part by part after the git log:

  • -p says display the patch for each commit after the commit body
  • --reverse displays commits in reverse chronological order
  • --format='%n%b' says “insert a new line, and then output the body(no subject line) of the commit
  • master.. says “display all commits between curren HEAD and master”

In this scenario, master.. means “all commits since master”, but you could just as easily insert a sha here, or a tag name on either side of the .. to capture a range of your history.

If you are writing commit messages the way that you should be, the output of this is a very nice skeleton of a blog post. I have just been redirecting (>) into a file named something like <post_name>.md and working off of that.

That’s all for now dear readers, go forth and git log your way onto the internet!