Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2014 17:58
What would you like to do?
including git-hash in a C program.
#ifndef GIT_HASH
#define GIT_HASH "f2607d7e246549d9ea54922a87001459c0235486"
a.out: test.c githash.h
gcc $<
echo -n '#ifndef GIT_HASH\n#define GIT_HASH "' > $@ && \
git rev-parse HEAD | tr -d "\n" >> $@ && \
echo '"\n#endif' >> $@
rm -f githash.h
#include <stdio.h>
#include "githash.h"
int main(int argc,char** argv)
return fputs("Git-Version:" GIT_HASH "\n",stdout)==0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment