antogno / gitinfo
GitInfo 是一个工具,可以让您获取当前 Git 仓库的信息
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2024-09-26 16:07:29 UTC
README
GitInfo 是一个工具,可以让您获取当前 Git 仓库的信息。
安装
使用依赖管理器 Composer 安装 GitInfo。
$ composer require antogno/gitinfo
用法
use antogno\GitInfo\GitInfo; $GitInfo = new GitInfo();
获取 Git 版本
$GitInfo->getGitVersion(); // For example: string(6) "2.40.0"
获取任何已删除的文件
$GitInfo->getDeletedFiles(false); // For example: array(2) { [0]=> string(13) "deleted_1.php" [1]=> string(13) "deleted_2.php" } $GitInfo->getDeletedFiles(true); // For example: array(2) { [0]=> string(36) "/Users/antogno/gitinfo/deleted_1.php" [1]=> string(36) "/Users/antogno/gitinfo/deleted_2.php" }
获取任何已修改的文件
$GitInfo->getModifiedFiles(false); // For example: array(2) { [0]=> string(14) "modified_1.php" [1]=> string(14) "modified_2.php" } $GitInfo->getModifiedFiles(true); // For example: array(2) { [0]=> string(37) "/Users/antogno/gitinfo/modified_1.php" [1]=> string(37) "/Users/antogno/gitinfo/modified_2.php" }
获取任何已重命名的文件
$GitInfo->getRenamedFiles(false); // For example: array(1) { ["old_name.php"]=> string(12) "new_name.php" } $GitInfo->getRenamedFiles(true); // For example: array(1) { ["/Users/antogno/gitinfo/old_name.php"]=> string(35) "/Users/antogno/gitinfo/new_name.php" }
获取任何未合并的文件
$GitInfo->getUnmergedFiles(false); // For example: array(2) { [0]=> string(14) "unmerged_1.php" [1]=> string(14) "unmerged_2.php" } $GitInfo->getUnmergedFiles(true); // For example: array(2) { [0]=> string(37) "/Users/antogno/gitinfo/unmerged_1.php" [1]=> string(37) "/Users/antogno/gitinfo/unmerged_2.php" }
获取任何未跟踪的文件
$GitInfo->getUntrackedFiles(false); // For example: array(2) { [0]=> string(15) "untracked_1.php" [1]=> string(15) "untracked_2.php" } $GitInfo->getUntrackedFiles(true); // For example: array(2) { [0]=> string(38) "/Users/antogno/gitinfo/untracked_1.php" [1]=> string(38) "/Users/antogno/gitinfo/untracked_2.php" }
获取任何已暂存的文件
$GitInfo->getStagedFiles(false); // For example: array(2) { [0]=> string(12) "modified.php" [1]=> string(11) "deleted.php" } $GitInfo->getStagedFiles(true); // For example: array(2) { [0]=> string(35) "/Users/antogno/gitinfo/modified.php" [1]=> string(34) "/Users/antogno/gitinfo/deleted.php" }
获取任何未暂存的文件
$GitInfo->getUnstagedFiles(false); // For example: array(2) { [0]=> string(12) "modified.php" [1]=> string(11) "deleted.php" } $GitInfo->getUnstagedFiles(true); // For example: array(2) { [0]=> string(35) "/Users/antogno/gitinfo/modified.php" [1]=> string(34) "/Users/antogno/gitinfo/deleted.php" }
作者
判断给定的作者是否存在
$GitInfo->hasAuthor('tonio.granaldi@gmail.com', 'antogno'); // For example: bool(true) $GitInfo->hasAuthor('', 'johndoe'); // For example: bool(false) $GitInfo->hasAuthor('TONIO.GRANALDI@GMAIL.COM', 'ANTOGNO'); // For example: bool(true)
获取当前提交的作者
$GitInfo->getCurrentCommitAuthor();
获取指定的作者(如果存在)
$GitInfo->getAuthor('tonio.granaldi@gmail.com', 'antogno'); $GitInfo->getAuthor('', 'antogno'); $GitInfo->getAuthor('TONIO.GRANALDI@GMAIL.COM');
获取作者列表
$GitInfo->getAuthors();
前三种方法都返回一个 AuthorResource
对象(或此类对象的列表)。
AuthorResource
use antogno\GitInfo\Resources\AuthorResource; $Author = new AuthorResource('tonio.granaldi@gmail.com', 'antogno'); $Author = new AuthorResource('', 'antogno'); $Author = new AuthorResource('TONIO.GRANALDI@GMAIL.COM');
获取作者姓名
$Author->getName(); // For example: string(7) "antogno"
获取作者电子邮件
$Author->getEmail(); // For example: string(24) "tonio.granaldi@gmail.com"
获取作者提交(CommitResource
列表)
$Author->getCommits();
分支
判断给定的分支是否存在
$GitInfo->hasBranch('master'); // For example: bool(true) $GitInfo->hasBranch('MASTER'); // For example: bool(false)
获取当前分支
$GitInfo->getCurrentBranch();
获取指定的分支(如果存在)
$GitInfo->getBranch('master');
获取分支列表
$GitInfo->getBranches();
前三种方法都返回一个 BranchResource
对象(或此类对象的列表)。
BranchResource
use antogno\GitInfo\Resources\BranchResource; $Branch = new BranchResource('master');
获取作者姓名
$Branch->getName(); // For example: string(6) "master"
获取分支的最后一个提交(CommitResource
)
$Branch->getLastCommit();
提交
判断具有给定哈希值的提交是否存在
$GitInfo->hasCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); // For example: bool(true) $GitInfo->hasCommit('ed8f932'); // For example: bool(true)
获取当前提交
$GitInfo->getCurrentCommit();
获取指定的提交(如果存在)
$GitInfo->getCommit('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); $GitInfo->getCommit('ed8f932');
获取提交列表
$GitInfo->getCommits();
前三种方法都返回一个 CommitResource
对象(或此类对象的列表)。
CommitResource
use antogno\GitInfo\Resources\CommitResource; $Commit = new CommitResource('ed8f9325485f108ddafe3890dc4b13be07aa13cb'); $Commit = new CommitResource('ed8f932');
获取长提交哈希值
$Commit->getLongHash(); // For example: string(40) "ed8f9325485f108ddafe3890dc4b13be07aa13cb"
获取短提交哈希值
$Commit->getShortHash(); // For example: string(7) "ed8f932"
获取提交信息
$Commit->getMessage(); // For example: string(14) "Initial commit"
获取提交日期(DateTime
)
$Commit->getDate();
获取提交作者(AuthorResource
)
$Commit->getAuthor();
标签
判断给定的标签是否存在
$GitInfo->hasTag('v1.0.0'); // For example: bool(true) $GitInfo->hasTag('V1.0.0'); // For example: bool(false)
获取当前标签(如果处于标签状态)
$GitInfo->getCurrentTag();
获取指定的标签(如果存在)
$GitInfo->getTag('v1.0.0');
获取标签列表
$GitInfo->getTags();
前三种方法都返回一个 TagResource
对象(或此类对象的列表)。
TagResource
use antogno\GitInfo\Resources\TagResource; $Tag = new TagResource('v1.0.0');
获取标签名称
$Tag->getName(); // For example: string(6) "v1.0.0"
获取标签的最后一个提交(CommitResource
)
$Tag->getLastCommit();
远程
判断给定的远程是否存在
$GitInfo->hasRemote('origin'); // For example: bool(true) $GitInfo->hasRemote('ORIGIN'); // For example: bool(false)
获取当前分支跟踪的远程
$GitInfo->getCurrentRemote();
获取指定的远程(如果存在)
$GitInfo->getRemote('origin');
获取远程列表
$GitInfo->getRemotes();
前三种方法都返回一个 RemoteResource
对象(或此类对象的列表)。
RemoteResource
use antogno\GitInfo\Resources\RemoteResource; $Remote = new RemoteResource('origin');
获取远程名称
$Remote->getName(); // For example: string(6) "origin"
获取远程 URL
$Remote->getUrl(); // For example: string(38) "https://github.com/antogno/gitinfo.git"
许可协议
GitInfo 根据 Creative Commons Zero v1.0 Universal 许可协议 许可。
更多详细信息,请访问 Creative Commons 网站。