Friday, March 9, 2012

Git Tagging

So, I'm setting up a GIT rep to track my company accounting files. Why? Quickbooks. The files are a moral hazard when, say, the software clobbers the data file, or an update goes awry, or you need to take a snapshot and then the software forgets which one was open. It can get really ugly. GIT ensures that only one file name need ever be present by doing the snap-shooting for you.

I know it is a lot of trouble, but there are two reasons that motivated me to do this: using file-name mangling is a wholly inadequate means of implementing revision control, and keeping the files locked down on one computer or on one network is risky and disruptive to getting things done when you move around to different machines. Under GIT, I fetch my accounting repo, make changes, commit and push the commit back to the remote. If I know I'm going to be moving around to another machine, I can clone into a Dropbox or other network folder and after I commit I can feel secure in removing the clone.

Of course, GIT won't version the Quickbooks file itself in any meaningful way. You can't for instance go back to a previous commit, branch it, and start applying journal debits and credits as corrections, and then merge back into the main line. Just won't work, because a QuickBooks data file is an opaque indexed binary structure, not a line-structured source file. 

But we can avoid mangling the file name for snapshot purposes. Yet if we don't mangle names, how will we know which commit is which without relying upon the comments? The answer lies in GIT tagging.
you're it

There are two types of tags in GIT, and either would work for this purpose.

The first is lightweight tagging. A lightweight tag is one without other metadata -- things like the tag creator, the date of tagging, and a GPG signature.  If all you care about is finding a particular commit given a label, then this is what you'll want:

git tag FiscalYear2011-Final

The only thing this does is point the tag to the current commit.

The second kind of tag is an annotated tag. Here, you tell GIT to make an object with the metadata, and/or a signature:

git tag -a FiscalYear2012-Start -m 'Beginning use of GIT'

We can list tags with:

git tag

and show the metadata for a tag with:

git show FiscalYear2012-Start
or use a script to give you a summary report:

for c in $(git tag -l)
  git show --quiet "$c"

If you really want to go hog wild, you can apply a digital signature, and verify it.  We're really only making read-only snapshots, and adding signing would be a good property for internal data auditing.

More info on tagging at github.


Anonymous said...

Very helpful explanation of Git tagging. Thanks!

Anonymous said...

Good explanation of tagging.