How to get Git version history embedded to source code?

321 Views Asked by At

In SO, there are some questions related how to get Git automatically append file change details (e.g. author, date, version number, short description of change, etc), using similar kind of keywords/tags/hashes as is used in RCS/CVS and most other systems. There were no clear answers, how to do this - mainly there were warnings to not do it.

I do realize that it is possible to get the same information using Git's own history methods, but in this real life, when programmers have used to old methods, it just makes the life easier when file's version history is embedded to file's header.

Question: how can the change information be automatically inserted into file header during commit phase?

1

There are 1 best solutions below

0
On

I still don't understand, why (requirement management wise) that feature wasn't specified into Git in the first place

Because you are supposed to get that information from Git itself, not from the file content (managed by Git)

That being said, I have seen alternative approaches, like generating a file will all the Git metadata you need in it (done after all commits), and packaged in the deliverable, meaning:

  • not the sources (managed by Git)
  • but the end result produced by the compilation of the source.

That way, your final program can still access those metadata during its execution.