This is my blog, there are many others like it but this one is mine.

Using Git to generate an automatic version number

With one of the most recent projects which clocks in at 6331 lines of code, it becomes difficult to determine whether the production and development versions are running the same version after a number of commits.

You can use either the projectversion or the cleanversion depending on the format you prefer.

The projectversion will contain the sha snippet along with the version and looks like: 1.0-1-g8f63877-291.

The cleanversion removes the sha key leaving 1.0-291.

Now that we’ve got a version number that changes on each commit, we can use this somewhere. This version is updated AFTER the last commit, so, you’ll want to import it into your project somewhere, or, in your commit message.

Before you commit, as one of the commenters in the previous post said, execute:

You can do whatever you need with the post-commit script. I just chose to use bash to rewrite the version number present in the footer of the site. You can just output the version number to a header file that is included if that works with your system.

This entry was posted
on Thursday, February 2nd, 2012 at 6:00 am and is filed under Programming Languages.
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “Using Git to generate an automatic version number”

Hey, great post. Really needed to be able to do this. One small (knit-picky) note was that when I run the shell script git-revision.sh I was getting a big space between the projectversion and revisioncount variables. To fix, change I changed the following:
revisioncount=`git log --oneline | wc -l`