Github - how to include info in your source
Is their a way to inject last commit n开发者_运维知识库umber/branch information into your code files in github? Maybe using some kind of reserved word or token? I'm a little new to advanced source control and git so forgive if I'm not using the right terminology and feel free to rephrase question.
The answer is yes but it isn't recommended.
https://git.wiki.kernel.org/index.php/GitFaq#Does_git_have_keyword_expansion.3F
See Git FAQ for keyword expansion. The solution is to add an ident entry to .gitattributes about which files should be modified on checkin/checkout:
When the attribute ident is set for a path, git replaces $Id$ in the blob object with $Id:, followed by the 40-character hexadecimal blob object name, followed by a dollar sign $ upon checkout. Any byte sequence that begins with $Id: and ends with $ in the worktree file is replaced with $Id$ upon check-in.
It might be possible through your build system. In your build scripts you can execute git commands to get the necessary information and then pass these as macros in your code.
精彩评论