Is there a way to make git automatically generate a version number file for the -version option?

I have a project that is coming out of the alpha phase, and I am ready to start the release regularly. I know that GitHub has a โ€œmagicโ€ button, but I donโ€™t like the โ€œmagicโ€ functions at all, which I donโ€™t know exactly what they do:

https://github.com/blog/1547-release-your-software

As far as I can tell, this magic release feature on GitHub simply creates a tag in the source repository for a specific state of the code or uses an existing tag. According to this link, tag names should reflect the semantic version number, i.e. Major.Minor.Patch ex: v10.1.2 or something like that.

Typically, the accepted way for Git to do releases seems to be to just create tags. I would like to do this for Git to automatically create some kind of file in my code tree with the name of the version .txt or version.h file that contains the name of the Git tag that I created so that this file can be automatically when the user issues myporgram --version on the command line. Preferably, I would like to create an automatically generated header file, as it integrates into the binary when creating the program. Is there a way to do this automatically or do I need to automatically link the tag number in the file before I exit the git command?

+7
git github versioning command-line-arguments version
source share
1 answer

See a good solution here: https://coderwall.com/p/mk18zq/automatic-git-version-tagging-for-npm-modules

Basically, it's the other way around. Create a text file or header file. Lets say: Version.h:

#define VERSION 10.1.2 

Create a post-commit hook that looks for changes to the file. Expand: Change the version and commit the file. The hook will create the corresponding tag.

+4
source share

All Articles