How can I get the Git build number and embed it in a file?

前端 未结 6 1856
离开以前
离开以前 2020-12-14 21:43

I want to introduce a versioning constant grabbed from the version in Git. I know how to do this -- in a very hackish way in svn --

any ideas on how to do this with

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 21:56

    Instead of putting it in a text file then getting the contents of it each time, this appears to work quite well:

    sed -i.bak "s/$version = '.*';/$version = '`git rev-parse --short HEAD | tr -d '\n'`';/g" version.php
    

    where version.php looks like this:

    and then just include the file in your script as you would a settings file.

    You could also use git describe --all --long as your version string if you wanted to, I preferred the git-hash from git-ref-parse --short HEAD for my purposes.

    Or as a constant which may be better:

    sed -i.bak "s/define('VERSION','.*');/define('VERSION','`git describe --all --long | cut -d "-" -f 3`');/g" version.php
    

    and version.php:

提交回复
热议问题