Search code examples
linuxgitversion-controlauto-generate

How to auto-generate a version string in git


Possible Duplicate:
Enable ident string for Git repos

In my project, every source file (regardless of the language - Java, Python, shell) has a comment line that contains source control information - branch, date of last commit, committer name, etc.

This is done by using special placeholders (e.g. $Branch$) which are auto-replaced by the source control application.

Is it possible to achieve similar functionality in git?

I am using Git Extensions on Windows and yet-to-be-decided GUI on Linux, but I assume both are just GUIs that invoke the git command-line tools.


Solution

  • You have to read about smudge/clean filters in Git in order to get some iteration of keyword-replacement.

    Grok section "Keyword Expansion", where example of expanding $DATE$ keyword explained (and a must reverse-operation). In you case most work of expanding $SOMEKEYWORD$ to version string can be performed by git describe under the hood, clean part must be implemented by hand (your hand)