Version Numbers Using git tag, git describe
I’ve spent the past year doing all of my development using the Git version control system. It’s far better than than subversion and has made my job as project manager/developer/commit manager much easier.
However, since it does not use revision numbers like subversion it’s more difficult to include as build numbers or version numbers. I wanted some automated way to identify the build in some way other than a non-incremental SHA1-hash. The only solution I’ve been able to find (without using any external software) is as follows.
The workflow to make this process work as expected would involve the following:
- Prepare master for a new release. Create a new branch for the release and tag it with 1.0.
- Make a single commit on master (necessary to separate the history) and re-tag with something for the next revision, like 1.1-alpha.
- Tags on branch continue with 1.0-1, 1.0-2, etc. Tags on master continue with 1.1-alpha-1, 1.1-alpha-2, etc.
What’s problematic with this is the requirement to both tag and branch each time you want a release. You also need to add in a extra commit before re-tagging master so there’s an unwanted extra step.
Create a new repo for a test file:
$ echo "testing" > myfile
$ git init
$ git add .
$ git commit -m "testing"
No tags yet. Create branch for 1.0
$ git checkout -b 1.0
$ git tag -a 1.0 -m "Tagging for 1.0"
$ echo "changing my text" > myfile
$ git commit -a -m "updated"
$ git describe
At this point, you’ll see something like: 1.0-1-ga3548ab. And if you run describe on the master branch, it still will report as ’1.0′.
Now, you need to create a single commit on master to “begin” the flow towards the next release. I’d recommend manually updating some code or text in your files for the new major version, since you obviously want this to be a minor commit.
$ echo "changing my text for next release" > myfile
$ git commit -a -m "updated"
$ git tag -a 1.1-alpha -m "Beginning work on next release"
When you run describe on the master branch it will now report properly as “1.1-alpha”. Yet as you continue bugfixes on the 1.0 branch, it will stay as “1.0-2-g1f37eb1″, etc.
If you have more information or a better way (with or without external software) then please let me know.