Github - how to include info in your source

215 Views Asked by At

Is their a way to inject last commit number/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.

3

There are 3 best solutions below

0
On

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.

0
On
1
On

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.