how to include git commit-number into a c++ executable?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)