I want to display the Git version on my site.
How can I display a semantic version number from Git, that non-technical users of a site can easily reference when raising issues?
I want to display the Git version on my site.
How can I display a semantic version number from Git, that non-technical users of a site can easily reference when raising issues?
Firstly, some
git
commands to fetch version information:git log --pretty="%H" -n1 HEAD
git log --pretty="%h" -n1 HEAD
git log --pretty="%ci" -n1 HEAD
git describe --tags --abbrev=0
git describe --tags
Secondly, use
exec()
combined with the git commands of your choice from above to build the version identifier:Gist: https://gist.github.com/lukeoliff/5501074
I did it just as:
substr(file_get_contents(GIT_DIR.'/refs/heads/master'),0,7)
resource friendly and the same as i have under eclipse shown
If you'd like to do it without
exec()
and you're using git lightweight (see comments below) tagging:You can get the current HEAD commit hash from
.git/HEAD
or.git/refs/heads/master
. We then loop to find matching. Reversing the array first for speed because you're more likely to at a higher recent tag.So if the current php file sits in a
public_html
orwww
folder one level down from the.git
folder...Simple way:
$rev = exec('git rev-parse --short HEAD');
$rev = exec('git rev-parse HEAD');