How To Use Git As A Running Sheet


When you’re handling a technology meltdown (like a computer failure or a malware infection) it helps to have a running sheet of the things you’re doing to remedy the crisis. Using Git can be a very effective way to do that.

Frustration picture from Shutterstock

A running sheet should include entries that are time stamped and recorded in the order you do them; as these details that can be valuable later to reverse steps, or communicate to others who you might have to call in to help (like, when you need sleep).

In the old days I used to log my running sheet notes in Notepad (repeatedly pressing the F5 key to get the timestamp for each line) but eventually found this to be cumbersome and messy.

Enter Git — the totally awesome and free version control software, which apart from being used for tracking changes in source code, is also really good at logging simple one-line comments as well!

The script shown here gives you a simple log>prompt in a command window, where you keep typing every little thing as it happens and each time you hit the Enter key your entry is faithfully logged and time stamped for later retrieval if you need it.

What You’ll Need

You need to install Git — get that here for almost any platform including Windows, Mac and Linux.

When installing on Windows be sure to select the option ‘Run Git from the Windows Command Prompt’ as this will ensure you can run the script here which is a Shell Script (.sh extension).

Setting Up The Log Script

Before you can use the script you’ll need to create a new empty Git “repository” (which is just a folder on your computer with an extra .git folder created inside it) — this is easily done from a command prompt (just change the folder name “mynotes” as desired):

mkdir mynotes
cd mynotes
git init

Now copy the text below into a file called “log.sh” and save it inside the folder that you just created.


#!/bin/sh
clear
echo "Quick Logging (Press Enter on a blank line to exit)"
while true
do
	echo
	read -p "log> " logtext
	if test -z "$logtext"
	then
		exit 0
	else
		git commit --allow-empty -m "$logtext"
	fi
done

If you’re using Mac or Linux don’t forget you’ll also need to make the script executable:

chmod +x log.sh

How To Get Logging

Once you’ve got your log.sh file in place, create a shortcut for easy access if you need to, and double-click (on Windows) or execute it from a command window.

Reading Or Exporting Your Notes

This is where the genius of using Git comes in, most of which revolves around a simple command (just remember you need to be in the same folder as your repository):

git log

You can read more about the git log command elsewhere, which allows you to filter for date ranges or filter and so forth so you can extract what you want, but in most cases I just dump everything into a text file and edit or pass on what I need.

My favourite choice:

git log --pretty=format:"%ad: %s"

Which will return lines that have the full date followed by the comment on each line, for example:

Fri Feb 22 00:58:45 2013 +1100: reading how-to article on lifehacker.com.au for help
Fri Feb 22 00:58:24 2013 +1100: coming up with stop error 0x00000008
Fri Feb 22 00:57:26 2013 +1100: server still won’t boot properly
Fri Feb 22 00:57:14 2013 +1100: reinstalled service pack 1

This produces an effective running sheet, and improves your Git knowledge as well. Win-win!

Michael McKinnon is security advisor for AVG Australia. Follow him on Twitter @bigmac.


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


Leave a Reply