This gist shows how to automatically increment and add version numbers to your commit messages and source code.
The major and minor version numbers are managed manually using git tag, while the per-commit numbers are managed automatically with git hooks.
This example uses the following version numbering scheme:
v{MAJOR}.{MINOR}-c{COMMIT#}
Start out by running git tag -a v1.0 for the initial release
Internally, this will be referred to as "v1.0-c1"
The next commit made will automatically be incremented to "v1.0-c2", and so on...
If you need to increment the major or minor version number, add a new tag:
git tag -a v1.1
The commit counter will then be reset and the next commit will internally be referred to as "v1.1-c1"
These hooks prepend this internal version number to your commit messages and also optionally update it in the source code.
Thus, if you run git commit -m 'bugfix', the actual commit message will become [version] bugfix
Edit the pre-commit file as necessary to change the proper place in your code. For simplicity's sake, it assumes the initial version number "v1.0-c1" already exists in the code and uses this to figure out where the version number should be replaced.