antalaron / git-version
用于获取当前Git版本的PHP库
v1.4.0
2024-06-04 13:23 UTC
Requires
- php: >=5.5.9
Requires (Dev)
- phpunit/phpunit: ^4.0|^5.0|^6.0|^7.0|^8.0
Suggests
- ext-zlib: Needed to support extracting latest commit message
This package is auto-updated.
Last update: 2024-09-04 17:41:13 UTC
README
PHP库,用于获取项目的Git版本。
此库不依赖于Git。
安装
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此库的最新稳定版本
$ composer require antalaron/git-version
此命令要求您已全局安装Composer,请参阅Composer文档中的安装章节。
用法
获取版本
$gitVersion = new \Antalaron\GitVersion\GitVersion(); $gitVersion->getVersion(__DIR__); // or static \Antalaron\GitVersion\GitVersion::getGitVersion(__DIR__);
如果没有找到git,则返回值是 null
。
方法中还有一个名为 $hashLenght
的第二个参数。使用该参数,您将获取hash的前n个字符。
获取最新的提交消息
$gitVersion = new \Antalaron\GitVersion\GitVersion(); $gitVersion->getLatestCommit(__DIR__); // or static \Antalaron\GitVersion\GitVersion::getGitLatestCommit(__DIR__);
错误发生时,返回值是 null
。
获取最新的提交对象
$gitVersion = new \Antalaron\GitVersion\GitVersion(); $gitVersion->getLatestCommitDetails(__DIR__); // or static \Antalaron\GitVersion\GitVersion::getGitLatestCommitDetails(__DIR__);
许可证
本项目遵循MIT许可证。