質問

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.

役に立ちましたか?

解決 2

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)

他のヒント

Git does not have support for these placeholders and probably never will have.

Instead, automaticaly generate source file which contains output of git describe command and include it while compiling your application. Or you can generate some configuration file instead (JSON or whatever you want).

To generate C++ header with version info, use shell script like this (you can add these commands directly to your makefile):

(
  echo '/* Generated file, do not edit. */'
  echo  '#define APP_VERSION "'`git describe`'"'
  echo  '#define APP_VERSION_DATE "'`git log -n 1 --format=%ai`'"'
) > version.h

To do this for scripting languages you can use post-commit and other hooks.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top