I want to manage my code version using tags in git.
If I have a new release I create a new annotated tag, e.g. 1.3.0.
Now I would like to also have this version number available in the code itself.
To do this I tried using:
git describe --tags
And put the result in a file. Obviously I am always one tag behind. If I create a new tag 1.3.1.
the code will still refer to version 1.3.0
, only the following commits will refer to the new number.
Is there a clean workaround? With regular commits I could just use --amend
to overwrite the content once, but for tags this doesn't seem to exist.
Some context:
I am using python
with setuptools
. In my setup-file I use git describe --tags
and safe this as my version. Furthermore it is written to a file, if git is not installed the version is read from this file.
My python code then reads this file, to be able to print it's on version via ./script.py --version
.