we have a build system that uses the svn ID as an imput to a VM builder appliance that required a five digit number. When I build from git I have been faking this by counting the number of commits in the git repo. This only sort-of-works :-/ I'm tyring to figure out:
- how can I get a unique 5 digit number from the git repo.
You're looking for git describe:
You want to use git describe as said earlier, here is my rake task that prints out incrementing semver compliant version numbers automatically:
Used like this:
$> rake version
v0.9.8pre32-fcb661d
In git, every commit generates a unique SHA1 hash id. You can see the id for each commit when running
git log
. If you want a 5 digit number for the most recent commit, you could do something likegit log --pretty=oneline --abbrev-commit --abbrev=5 -1
. For one of my repos the output looks like this:You can experiment with the other options to
git log
to customize the format if needed. Of course, if the repository has enough commits, there's always the possibility that 5 digits will not be enough to guarantee uniqueness, but for small enough projects it may do.