How can I populate the Git commit ID into a file when I commit?

前端 未结 9 1456
生来不讨喜
生来不讨喜 2020-12-02 12:45

I would like to create Git hook(s) that will populate the commit id of the commit I am about to make into a file (basically variable substitution) in my source code. Is this

9条回答
  •  既然无缘
    2020-12-02 12:51

    OK, inspired by Jon Cairns' answer, I came up with this little snippet you could put in your Makefile.

    version.h:
            git log -n 1 --format=format:"#define GIT_COMMIT \"%h\"%n" HEAD > $@
    

    It's not a completely general solution, but it could come in handy. I know a place or two where I'll be using it.

提交回复
热议问题