i use git as a version tracker for my c++ project.
sometimes i need to repeat a calculation and i would like to know which version of the program i used.
wh
Probably the easiest way to do this would be to add to your makefile a rule to generate a .c file with the current git commit ID:
gitversion.c: .git/HEAD .git/index
echo "const char *gitversion = \"$(shell git rev-parse HEAD)\";" > $@
Now simply add gitversion.c
to your build process as normal. Make sure to remove it on make clean
, and add it to .gitignore
so it's not added to the git repository accidentally. Add an extern const char *gitversion;
to a header somewhere, and you can access it like that.