Display the current Git 'version' in PHP

前端 未结 6 707
醉话见心
醉话见心 2021-01-30 11:37

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

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 12:22

    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...

提交回复
热议问题