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
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
or www
folder one level down from the .git
folder...