tomk79 / phpgit
PHP5.3+ 的 Git 包装器
Requires
- php: >=5.4.0
- symfony/options-resolver: ^3.3
- symfony/process: ^3.3
Requires (Dev)
- phpunit/phpunit: ^4.8
- symfony/filesystem: ^3.3
This package is auto-updated.
Last update: 2024-09-25 16:00:42 UTC
README
tomk79/phpgit
是从 kzykhys/git
分支出来的,并进行了一些修改。
要求
- PHP5.3
- Git
安装
更新您的 composer.json 文件并运行 composer update
{ "require": { "tomk79/phpgit": "dev-master" } }
基本用法
<?php require __DIR__ . '/vendor/autoload.php'; $git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); $git->remote->add('production', 'git://example.com/your/repo.git'); $git->add('README.md'); $git->commit('Adds README.md'); $git->checkout('release'); $git->merge('master'); $git->push(); $git->push('production', 'release'); $git->tag->create('v1.0.1', 'release'); foreach ($git->tree('release') as $object) { if ($object['type'] == 'blob') { echo $git->show($object['file']); } }
API
Git 命令
- git add
- $git->add(string|array|\Traversable $file, array $options = [])
- git archive
- $git->archive(string $file, string $tree = null, string|array|\Traversable $path = null, array $options = [])
- git branch
- git cat-file
- git checkout
- git clone
- $git->clone(string $repository, string $path = null, array $options = [])
- git commit
- $git->commit(string $message, array $options = [])
- git config
- git describe
- git fetch
- git init
- $git->init(字符串 $path, 数组 $options = [])
- git log
- $git->log(字符串 $revRange = '', 字符串 $path = null, 数组 $options = [])
- git merge
- git mv
- $git->mv(字符串|数组|\Iterator $source, 字符串 $destination, 数组 $options = [])
- git pull
- $git->pull(字符串 $repository = null, 字符串 $refspec = null, 数组 $options = [])
- git push
- $git->push(字符串 $repository = null, 字符串 $refspec = null, 数组 $options = [])
- git rebase
- git remote
- $git->remote()
- $git->remote->add(字符串 $name, 字符串 $url, 数组 $options = [])
- $git->remote->rename(字符串 $name, 字符串 $newName)
- $git->remote->rm(字符串 $name)
- $git->remote->show(字符串 $name)
- $git->remote->prune(字符串 $name = null)
- $git->remote->head(字符串 $name, 字符串 $branch = null)
- $git->remote->head->set(字符串 $name, 字符串 $branch)
- $git->remote->head->delete(字符串 $name)
- $git->remote->head->remote(字符串 $name)
- $git->remote->branches(字符串 $name, 数组 $branches)
- $git->remote->branches->set(字符串 $name, 数组 $branches)
- $git->remote->branches->add(字符串 $name, 数组 $branches)
- $git->remote->url(字符串 $name, 字符串 $newUrl, 字符串 $oldUrl = null, 数组 $options = [])
- $git->remote->url->set(字符串 $name, 字符串 $newUrl, 字符串 $oldUrl = null, 数组 $options = [])
- 将 $git->remote->url 的结果添加新URL,使用 add(string $name, string $newUrl, array $options = []) 方法。
- 从 $git->remote->url 删除指定URL,使用 delete(string $name, string $url, array $options = []) 方法。
- git 重置
- 使用 reset(string|array|\Traversable $paths, string $commit = null)
- 使用 $git->reset 的 soft(string $commit = null)
- 使用 $git->reset 的 mixed(string $commit = null)
- 使用 $git->reset 的 hard(string $commit = null)
- 使用 $git->reset 的 merge(string $commit = null)
- 使用 $git->reset 的 keep(string $commit = null)
- 使用 $git->reset 的 mode(string $mode, string $commit = null)
- git 删除
- git 简短日志
- git 显示
- 使用 show(string $object, array $options = []) 方法
- git 存档
- 使用 $git->stash 的 stash() 方法
- 使用 $git->stash 的 save(string $message = null, array $options = []) 方法
- 使用 $git->stash 的 lists(array $options = []) 方法
- 使用 $git->stash 的 show(string $stash = null)
- 使用 $git->stash 的 drop(string $stash = null)
- 使用 $git->stash 的 pop(string $stash = null, array $options = []) 方法
- 使用 $git->stash 的 apply(string $stash = null, array $options = []) 方法
- 使用 $git->stash 的 branch(string $name, string $stash = null)
- 使用 $git->stash 的 clear() 方法
- 使用 $git->stash 的 create() 方法
- git 状态
- 使用 status(array $options = []) 方法
- git 标签
- git ls-tree
- $git->tree(string $branch = master, string $path = '')
git add
$git->add(string|array|\Traversable $file, array $options = [])
将文件内容添加到索引
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->add('file.txt'); $git->add('file.txt', ['force' => false, 'ignore-errors' => false);
选项
- force (boolean) 允许添加其他忽略的文件
- ignore-errors (boolean) 不中止操作
git archive
$git->archive(string $file, string $tree = null, string|array|\Traversable $path = null, array $options = [])
从命名树创建文件存档
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->archive('repo.zip', 'master', null, ['format' => 'zip']);
选项
- format (boolean) 结果存档的格式:tar 或 zip
- prefix (boolean) 在存档中的每个文件名前添加前缀/
git branch
$git->branch(array $options = [])
返回远程跟踪分支和本地分支的数组
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $branches = $git->branch();
输出示例
[
'master' => ['current' => true, 'name' => 'master', 'hash' => 'bf231bb', 'title' => 'Initial Commit'],
'origin/master' => ['current' => false, 'name' => 'origin/master', 'alias' => 'remotes/origin/master']
]
选项
- all (boolean) 列出远程跟踪分支和本地分支
- remotes (boolean) 列出远程跟踪分支
$git->branch->create(string $branch, string $startPoint = null, array $options = [])
创建一个名为 $branch 的新分支头,它指向当前的 HEAD,或者如果给定 $startPoint,则指向它
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->branch->create('bugfix'); // from current HEAD $git->branch->create('patch-1', 'a092bf7s'); // from commit $git->branch->create('1.0.x-fix', 'v1.0.2'); // from tag
选项
- force (boolean) 如果 $branch 已存在,则将 $branch 重置为 $startPoint
$git->branch->move(string $branch, string $newBranch, array $options = [])
移动/重命名分支及其相应的 reflog
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->branch->move('bugfix', '2.0');
选项
- force (boolean) 即使新分支名称已存在,也移动/重命名分支
$git->branch->delete(string $branch, array $options = [])
删除分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->branch->delete('2.0');
该分支必须完全合并到其上游分支,或者在没有设置 --track 或 --set-upstream 的情况下合并到 HEAD。
选项
- force (boolean) 不考虑合并状态删除分支
git cat-file
$git->cat->blob(string $object)
返回 blob 对象的内容
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
$git->cat->type(string $object)
返回由 $object 标识的对象类型
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
$git->cat->size(string $object)
返回由 $object 标识的对象大小
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
git checkout
$git->checkout(string $branch, array $options = [])
通过更新索引、工作树和 HEAD 来切换分支,以反映指定的分支或提交
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout('develop');
选项
- force (boolean) 即使索引或工作树与 HEAD 不同,也要继续进行
- merge (boolean) 合并本地修改
$git->checkout->rollback(string $hash, string $path, array $options = [])
创建新分支并检出
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout->rollback('HEAD',array('path'=>'path/to/rollback/'));
选项
- force (boolean) 即使索引或工作树与 HEAD 不同,也要继续进行
$git->checkout->create(string $branch, string $startPoint = null, array $options = [])
创建新分支并检出
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout->create('patch-1'); $git->checkout->create('patch-2', 'develop');
选项
- force (boolean) 即使索引或工作树与 HEAD 不同,也要继续进行
$git->checkout->orphan(string $branch, string $startPoint = null, array $options = [])
创建一个名为 <new_branch> 的新孤儿分支,从 <start_point> 开始,并切换到它
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout->orphan('gh-pages');
选项
- force (boolean) 即使索引或工作树与 HEAD 不同,也要继续进行
git clone
$git->clone(string $repository, string $path = null, array $options = [])
将存储库克隆到新目录中
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
选项
- shared (boolean) 开始时没有任何自己的对象
- bare (boolean) 创建裸 Git 存储库
git commit
$git->commit(string $message, array $options = [])
将更改记录到存储库
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); $git->add('README.md'); $git->commit('Fixes README.md');
选项
- all (boolean) 索引已修改和已删除的文件
- reuse-message (string) 采取现有的提交对象,并在创建提交时重用日志消息和作者信息(包括时间戳)
- squash (string) 为 rebase --autosquash 构造提交消息
- author (string) 覆盖提交作者
- 日期 (字符串) 覆盖提交中使用的作者日期
- 清理 (字符串) 可以是 verbatim、whitespace、strip 和 default 之一
- 修改 (布尔值) 用于修改当前分支的顶端
git config
$git->config(数组 $options = [])
返回配置文件中设置的 所有变量
选项
- 全局 (布尔值) 读取或写入当前用户的配置选项
- 系统 (布尔值) 读取或写入当前机器上所有用户的配置选项
$git->config->set(字符串 $name, 字符串 $value, 数组 $options = [])
设置一个选项
选项
- 全局 (布尔值) 读取或写入当前用户的配置选项
- 系统 (布尔值) 读取或写入当前机器上所有用户的配置选项
$git->config->add(字符串 $name, 字符串 $value, 数组 $options = [])
在不更改任何现有值的情况下,向选项中添加一行新内容
选项
- 全局 (布尔值) 读取或写入当前用户的配置选项
- 系统 (布尔值) 读取或写入当前机器上所有用户的配置选项
git describe
$git->describe(字符串 $committish = null, 数组 $options = [])
返回可以从提交访问到的最新标签
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->tag->create('v1.0.0'); $git->commit('Fixes #14'); echo $git->describe('HEAD', ['tags' => true]);
输出示例
v1.0.0-1-g7049efc
选项
- 所有 (布尔值) 启用匹配任何已知分支、远程跟踪分支或轻量标签
- 标签 (布尔值) 启用匹配轻量(非注释)标签
- 始终 (布尔值) 以唯一缩略的提交对象作为后备显示
$git->describe->tags(字符串 $committish = null, 数组 $options = [])
等同于 $git->describe($committish, ['tags' => true]);
git fetch
$git->fetch(字符串 $repository, 字符串 $refspec = null, 数组 $options = [])
从一个或多个其他仓库中获取命名头部或标签,以及完成它们的必要对象
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'git://your/repo.git'); $git->fetch('origin');
选项
- 追加 (布尔值) 将获取的引用的名称和对象名称追加到 .git/FETCH_HEAD 的现有内容中
- 保留 (布尔值) 保留下载的包
- 修剪 (布尔值) 在获取后,删除远程上不再存在的任何远程跟踪分支
$git->fetch->all(数组 $options = [])
获取所有远程仓库
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'git://your/repo.git'); $git->remote->add('release', 'git://your/another_repo.git'); $git->fetch->all();
选项
- 追加 (布尔值) 将获取的引用的名称和对象名称追加到 .git/FETCH_HEAD 的现有内容中
- 保留 (布尔值) 保留下载的包
- 修剪 (布尔值) 在获取后,删除远程上不再存在的任何远程跟踪分支
git init
$git->init(字符串 $path, 数组 $options = [])
创建一个空的 git 仓库或重新初始化现有的仓库
$git = new PHPGit\Git(); $git->init('/path/to/repo1'); $git->init('/path/to/repo2', array('shared' => true, 'bare' => true));
选项
- 共享 (布尔值) 指定 git 仓库将由多个用户共享
- 裸 (布尔值) 创建一个裸仓库
git log
$git->log(字符串 $revRange = '', 字符串 $path = null, 数组 $options = [])
返回提交日志
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $logs = $git->log(array('limit' => 10));
输出示例
[ 0 => [ 'hash' => '1a821f3f8483747fd045eb1f5a31c3cc3063b02b', 'name' => 'John Doe', 'email' => 'john@example.com', 'date' => 'Fri Jan 17 16:32:49 2014 +0900', 'title' => 'Initial Commit' ], 1 => [ //... ] ]
选项
- 限制 (整数) 限制要显示的提交数量
- 跳过 (整数) 在开始显示提交输出之前跳过指定数量的提交
git merge
$git->merge(字符串|array|\Traversable $commit, 字符串 $message = null, 数组 $options = [])
将命名提交中的更改合并到当前分支中
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->merge('1.0'); $git->merge('1.1', 'Merge message', ['strategy' => 'ours']);
选项
- no-ff (布尔值) 如果合并解析为快速前进,则不生成合并提交,仅更新分支指针
- rerere-autoupdate (布尔值) 允许 rerere 机制在可能的情况下使用自动冲突解决的成果更新索引
- 压缩 (布尔值) 允许你在当前分支的顶部创建一个单一提交,其效果与合并另一个分支相同
- 策略 (字符串) 使用给定的合并策略
- 策略选项 (字符串) 通过合并策略传递特定的合并策略选项
$git->merge->abort()
中止合并过程并尝试重建预合并状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); try { $git->merge('dev'); } catch (PHPGit\Exception\GitException $e) { $git->merge->abort(); }
git mv
$git->mv(字符串|array|\Iterator $source, 字符串 $destination, 数组 $options = [])
移动或重命名文件、目录或符号链接
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->mv('UPGRADE-1.0.md', 'UPGRADE-1.1.md');
选项
- 强制 (布尔值) 即使目标存在也强制重命名或移动文件
git pull
$git->pull(字符串 $repository = null, 字符串 $refspec = null, 数组 $options = [])
从另一个仓库或本地分支获取并合并
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->pull('origin', 'master');
git push
$git->push(字符串 $repository = null, 字符串 $refspec = null, 数组 $options = [])
更新远程引用及其关联的对象
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->push('origin', 'master');
git rebase
$git->rebase(string $upstream = null, string $branch = null, array $options = [])
将本地提交向前移植到更新的上游头部
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->fetch('origin'); $git->rebase('origin/master');
选项
- onto (string) 创建新提交的起始点
- no-verify (boolean) 跳过预变基钩子
- force-rebase (boolean) 强制变基,即使当前分支是你要变基到其上的提交的后代
$git->rebase->continues()
解决合并冲突后重新启动变基过程
$git->rebase->abort()
中止变基操作并将HEAD重置到原始分支
$git->rebase->skip()
跳过当前补丁重新启动变基过程
git remote
$git->remote()
返回现有远程仓库数组
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); $remotes = $git->remote();
输出示例
[ 'origin' => [ 'fetch' => 'https://github.com/kzykhys/Text.git', 'push' => 'https://github.com/kzykhys/Text.git' ] ]
$git->remote->add(string $name, string $url, array $options = [])
为位于 $url 的仓库添加名为 $name 的远程
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->fetch('origin');
选项
- tags (boolean) 使用此选项,
git fetch <name>
从远程仓库导入所有标签 - no-tags (boolean) 使用此选项,
git fetch <name>
不从远程仓库导入标签
$git->remote->rename(string $name, string $newName)
将名为 $name 的远程重命名为 $newName
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->rename('origin', 'upstream');
$git->remote->rm(string $name)
删除名为 $name 的远程
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->rm('origin');
$git->remote->show(string $name)
提供关于远程 $name 的某些信息
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); echo $git->remote->show('origin');
输出示例
\* remote origin
Fetch URL: https://github.com/kzykhys/Text.git
Push URL: https://github.com/kzykhys/Text.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
$git->remote->prune(string $name = null)
删除所有在 $name 下的过时远程跟踪分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->prune('origin');
$git->remote->head(string $name, string $branch = null)
set() 的别名
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->head('origin');
$git->remote->head->set(string $name, string $branch)
为命名的远程设置默认分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->head->set('origin');
$git->remote->head->delete(string $name)
删除命名的远程的默认分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->head->delete('origin');
$git->remote->head->remote(string $name)
通过查询远程确定默认分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->head->remote('origin');
$git->remote->branches(string $name, array $branches)
set() 的别名
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->branches('origin', array('master', 'develop'));
$git->remote->branches->set(string $name, array $branches)
更改命名的远程跟踪的分支列表
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->branches->set('origin', array('master', 'develop'));
$git->remote->branches->add(string $name, array $branches)
将分支添加到命名的远程跟踪列表中
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->branches->add('origin', array('master', 'develop'));
$git->remote->url(string $name, string $newUrl, string $oldUrl = null, array $options = [])
set() 的别名
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->url('origin', 'https://github.com/text/Text.git');
选项
- push (boolean) 操作推送到URL而不是获取URL
$git->remote->url->set(string $name, string $newUrl, string $oldUrl = null, array $options = [])
将远程URL设置为 $newUrl
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->url->set('origin', 'https://github.com/text/Text.git');
选项
- push (boolean) 操作推送到URL而不是获取URL
$git->remote->url->add(string $name, string $newUrl, array $options = [])
向远程添加新URL
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->url->add('origin', 'https://github.com/text/Text.git');
选项
- push (boolean) 操作推送到URL而不是获取URL
$git->remote->url->delete(string $name, string $url, array $options = [])
删除所有匹配正则表达式 $url 的URL
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->remote->add('origin', 'https://github.com/kzykhys/Text.git'); $git->remote->url->delete('origin', 'https://github.com');
选项
- push (boolean) 操作推送到URL而不是获取URL
git 重置
$git->reset(string|array|\Traversable $paths, string $commit = null)
将所有 $paths 的索引条目重置为其在 $commit 中的状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset();
$git->reset->soft(string $commit = null)
将当前分支头重置为 $commit
不触及索引文件或工作树(但将头重置为 $commit,就像所有模式一样)。这会将所有更改的文件保留为“待提交的更改”,就像git状态会显示的那样。
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->soft();
$git->reset->mixed(string $commit = null)
将当前分支头重置为 $commit
重置索引但不重置工作树(即,保留更改的文件但不标记为提交)并报告未更新的内容。这是默认操作。
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->mixed();
$git->reset->hard(string $commit = null)
将当前分支头重置为 $commit
重置索引和工作树。自 $commit 以来工作树中跟踪文件的任何更改都将被丢弃
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->hard();
$git->reset->merge(string $commit = null)
将当前分支头重置为 $commit
重置索引并更新工作树中与 $commit 和 HEAD 不同的文件,但保留与索引和工作树不同的文件(即尚未添加更改的文件)。如果与 $commit 和索引不同的文件有未提交的更改,则重置操作中止
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->merge();
$git->reset->keep(string $commit = null)
将当前分支头重置为 $commit
重置索引条目并更新工作树中与 $commit 和 HEAD 不同的文件。如果与 $commit 和 HEAD 不同的文件有本地更改,则重置操作中止。
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->keep();
$git->reset->mode(string $mode, string $commit = null)
将当前分支头重置为 $commit
根据 $mode 可能更新索引(将其重置为 $commit 的树)和工作树
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->reset->mode('hard');
git 删除
$git->rm(string|array|\Traversable $file, array $options = [])
从工作树和索引中删除文件
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->rm('CHANGELOG-1.0-1.1.txt', ['force' => true]);
选项
- force (boolean) 覆盖更新检查
- cached (boolean) 仅从索引中取消跟踪和删除路径
- recursive (boolean) 当给定前导目录名时允许递归删除
$git->rm->cached(string|array|\Traversable $file, array $options = [])
相当于 $git->rm($file, ['cached' => true]);
选项
- force (boolean) 覆盖更新检查
- recursive (boolean) 当给定前导目录名时允许递归删除
git 简短日志
$git->shortlog(string|array|\Traversable $commits = HEAD)
总结 'git log' 输出
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $shortlog = $git->shortlog();
输出示例
[ 'John Doe <john@example.com>' => [ 0 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-10 12:56:15 +0300'), 'subject' => 'Update README'], 1 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-15 12:56:15 +0300'), 'subject' => 'Update README'], ], //... ]
$git->shortlog->summary(string $commits = HEAD)
抑制提交描述,仅提供提交计数摘要
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $shortlog = $git->shortlog->summary();
输出示例
[ 'John Doe <john@example.com>' => 153, //... ]
git 显示
$git->show(string $object, array $options = [])
显示一个或多个对象(blob、tree、tags 和提交)
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); echo $git->show('3ddee587e209661c8265d5bfd0df999836f6dfa2');
选项
- format (string) 以给定格式格式化提交日志的内容,其中可以是 oneline、short、medium、full、fuller、email、raw 和 format 之一
- abbrev-commit (boolean) 不显示完整的 40 字节十六进制提交对象名称,而只显示部分前缀
git 存档
$git->stash()
将您的本地修改保存到一个新的暂存区域,并运行 git reset --hard 来撤销它们
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash();
$git->stash->save(string $message = null, array $options = [])
将您的本地修改保存到一个新的暂存区域,并运行 git reset --hard 来撤销它们。
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->save('My stash');
$git->stash->lists(array $options = [])
返回您目前拥有的暂存区域
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $stashes = $git->stash->lists();
输出示例
[ 0 => ['branch' => 'master', 'message' => '0e2f473 Fixes README.md'], 1 => ['branch' => 'master', 'message' => 'ce1ddde Initial commit'], ]
$git->stash->show(string $stash = null)
以暂存状态与其原始父状态之间的差异的形式显示暂存中记录的更改
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); echo $git->stash->show('stash@{0}');
输出示例
REAMDE.md | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
$git->stash->drop(string $stash = null)
从暂存列表中删除单个暂存状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->drop('stash@{0}');
$git->stash->pop(string $stash = null, array $options = [])
从暂存列表中删除单个暂存状态并将其应用到当前工作树状态之上
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->pop('stash@{0}');
$git->stash->apply(string $stash = null, array $options = [])
与 pop 类似,但不会从暂存列表中删除状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->apply('stash@{0}');
$git->stash->branch(string $name, string $stash = null)
创建并检出一个新的分支,该分支从最初创建的提交开始,并将记录的更改应用到新的工作树和索引中
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->branch('hotfix', 'stash@{0}');
$git->stash->clear()
删除所有暂存状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->stash->clear();
$git->stash->create()
创建一个暂存(这是一个常规的提交对象)并返回其对象名称,而无需将其存储在 ref 命名空间中的任何地方
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $commit = $git->stash->create();
输出示例
877316ea6f95c43b7ccc2c2a362eeedfa78b597d
git 状态
$git->status(array $options = [])
返回工作树状态
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $status = $git->status();
常量
- StatusCommand::UNMODIFIED [=' '] 未修改
- StatusCommand::MODIFIED [='M'] 修改
- StatusCommand::ADDED [='A'] 添加
- StatusCommand::DELETED [='D'] 删除
- StatusCommand::RENAMED [='R'] 重命名
- StatusCommand::COPIED [='C'] 复制
- StatusCommand::UPDATED_BUT_UNMERGED [='U'] 更新但未合并
- StatusCommand::UNTRACKED [='?'] 未跟踪
- 状态命令::IGNORED [='!'] 被忽略
输出示例
[ 'branch' => 'master', 'changes' => [ ['file' => 'item1.txt', 'index' => 'A', 'work_tree' => 'M'], ['file' => 'item2.txt', 'index' => 'A', 'work_tree' => ' '], ['file' => 'item3.txt', 'index' => '?', 'work_tree' => '?'], ] ]
选项
- 被忽略 (布尔值) 同时显示被忽略的文件
git 标签
$git->tag()
返回一个标签数组
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); $tags = $git->tag();
输出示例
['v1.0.0', 'v1.0.1', 'v1.0.2']
$git->tag->create(字符串 $tag, 字符串 $commit = null, 数组 $options = [])
创建一个标签对象
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->tag->create('v1.0.0');
选项
- annotate (布尔值) 创建一个未签名、带注释的标签对象
- sign (布尔值) 使用默认电子邮件地址的密钥创建GPG签名的标签
- force (布尔值) 用给定名称替换现有标签(而不是失败)
$git->tag->delete(字符串|array|\Traversable $tag)
删除具有给定名称的现有标签
$git->tag->verify(字符串|array|\Traversable $tag)
验证给定标签名称的gpg签名
git ls-tree
$git->tree(字符串 $branch = master, 字符串 $path = '')
返回树对象的内容
$git = new PHPGit\Git(); $git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo'); $git->setRepository('/path/to/repo'); $tree = $git->tree('master');
输出示例
[ ['mode' => '100644', 'type' => 'blob', 'hash' => '1f100ce9855b66111d34b9807e47a73a9e7359f3', 'file' => '.gitignore', 'sort' => '2:.gitignore'], ['mode' => '100644', 'type' => 'blob', 'hash' => 'e0bfe494537037451b09c32636c8c2c9795c05c0', 'file' => '.travis.yml', 'sort' => '2:.travis.yml'], ['mode' => '040000', 'type' => 'tree', 'hash' => '8d5438e79f77cd72de80c49a413f4edde1f3e291', 'file' => 'bin', 'sort' => '1:.bin'], ]
许可
MIT许可
作者
林修一希(@kzykhys)