kzykhys / git
PHP5.3+ 的 Git 封装器
Requires
- php: >=5.3.2
- symfony/options-resolver: >=2.3
- symfony/process: >=2.3
Requires (Dev)
- symfony/filesystem: >=2.3
This package is not auto-updated.
Last update: 2024-09-10 01:58:31 UTC
README
要求
- PHP5.3
- Git
安装
更新 composer.json 并运行 composer update
{ "require": { "kzykhys/git": "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->add(字符串 $name, 字符串 $newUrl, 数组 $options = [])
- $git->remote->url->delete(字符串 $name, 字符串 $url, 数组 $options = [])
- git reset
- $git->reset(字符串|array|\Traversable $paths, 字符串 $commit = null)
- $git->reset->soft(字符串 $commit = null)
- $git->reset->mixed(字符串 $commit = null)
- $git->reset->hard(字符串 $commit = null)
- $git->reset->merge(字符串 $commit = null)
- $git->reset->keep(字符串 $commit = null)
- $git->reset->mode(字符串 $mode, 字符串 $commit = null)
- git rm
- git shortlog
- git show
- $git->show(字符串 $object, 数组 $options = [])
- git stash
- $git->stash()
- $git->stash->save(字符串 $message = null, 数组 $options = [])
- $git->stash->lists(数组 $options = [])
- $git->stash->show(字符串 $stash = null)
- $git->stash->drop(字符串 $stash = null)
- $git->stash->pop(字符串 $stash = null, 数组 $options = [])
- $git->stash->apply(字符串 $stash = null, 数组 $options = [])
- $git->stash->branch(字符串 $name, 字符串 $stash = null)
- $git->stash->clear()
- $git->stash->create()
- git status
- $git->status(数组 $options = [])
- git tag
- git ls-tree
- $git->tree(字符串 $branch = master, 字符串 $path = '')
git add
$git->add(字符串|数组|\Traversable $file, 数组 $options = [])
将文件内容添加到索引
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->add('file.txt'); $git->add('file.txt', ['force' => false, 'ignore-errors' => false);
选项
- force (布尔值) 允许添加通常会被忽略的文件
- ignore-errors (布尔值) 不终止操作
git archive
$git->archive(字符串 $file, 字符串 $tree = null, 字符串|数组|\Traversable $path = null, 数组 $options = [])
从命名树创建文件存档
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->archive('repo.zip', 'master', null, ['format' => 'zip']);
选项
- format (布尔值) 结果存档的格式:tar 或 zip
- prefix (布尔值) 在存档中的每个文件名前添加前缀/prefix
git branch
$git->branch(数组 $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 (布尔值) 列出远程跟踪分支和本地分支
- remotes (布尔值) 列出远程跟踪分支
$git->branch->create(字符串 $branch, 字符串 $startPoint = null, 数组 $options = [])
创建一个名为 $branch 的新分支头,指向当前 HEAD,或者如果给出 $startPoint,则指向 $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 (布尔值) 如果 $branch 已存在,则重置 $branch 到 $startPoint
$git->branch->move(字符串 $branch, 字符串 $newBranch, 数组 $options = [])
移动/重命名分支及其对应的reflog
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->branch->move('bugfix', '2.0');
选项
- force (布尔值) 即使新分支名已存在,也移动/重命名分支
$git->branch->delete(字符串 $branch, 数组 $options = [])
删除分支
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->branch->delete('2.0');
分支必须完全合并到其上游分支,或者在未设置 --track 或 --set-upstream 的情况下合并到 HEAD。
选项
- force (布尔值) 不考虑合并状态删除分支
git cat-file
$git->cat->blob(字符串 $object)
返回 blob 对象的内容
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
$git->cat->type(字符串 $object)
返回由 $object 识别的对象类型
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
$git->cat->size(字符串 $object)
返回由 $object 识别的对象大小
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
git checkout
$git->checkout(字符串 $branch, 数组 $options = [])
通过更新索引、工作树和 HEAD 来切换分支,以反映指定的分支或提交
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout('develop');
选项
- force (布尔值) 即使索引或工作树与 HEAD 不同,也要继续操作
- merge (布尔值) 合并本地修改
$git->checkout->create(字符串 $branch, 字符串 $startPoint = null, 数组 $options = [])
创建新分支并检出
$git = new PHPGit\Git(); $git->setRepository('/path/to/repo'); $git->checkout->create('patch-1'); $git->checkout->create('patch-2', 'develop');
选项
- force (布尔值) 即使索引或工作树与 HEAD 不同,也要继续操作
$git->checkout->orphan(字符串 $branch, 字符串 $startPoint = null, 数组 $options = [])
创建一个新的孤儿分支,命名为 将仓库克隆到新目录 记录对仓库的更改 返回在配置文件中设置的变量 设置选项 向选项中添加新行而不修改任何现有值 返回从提交可到达的最新的标签 等同于 $git->describe($committish, ['tags' => true]); 从一个或多个其他仓库中获取命名头或标签,以及完成它们所需的对象 获取所有远程仓库 创建一个空 git 仓库或重新初始化现有的一个 返回提交日志 将指定提交中的更改合并到当前分支 中止合并过程并尝试重建合并前的状态 移动或重命名文件、目录或符号链接 从另一个仓库或本地分支获取并合并 更新远程引用及其相关对象 将本地提交正向移植到更新的上游头 在解决合并冲突后重新启动 rebase 过程 终止 rebase 操作并将 HEAD 重置到原始分支 通过跳过当前补丁重新启动 rebase 过程 返回现有远程的数组 为位于 $url 的存储库添加名为 $name 的远程 将名为 $name 的远程重命名为 $newName 删除名为 $name 的远程 提供关于远程 $name 的某些信息 删除 $name 下的所有过时远程跟踪分支 set() 的别称 设置指定远程的默认分支 删除指定远程的默认分支 通过查询远程确定默认分支 set() 的别称 更改指定远程跟踪的分支列表 添加到指定远程跟踪的分支列表中 set() 的别称 将远程 URL 设置为 $newUrl 向远程添加新 URL 删除所有与正则表达式 $url 匹配的 URL 将所有 $paths 的索引条目重置为 $commit 的状态 将当前分支头重置为 $commit 完全不触及索引文件和工作树(但重置 head 到 $commit,就像所有模式一样)。这会保留所有已更改的文件为“待提交的更改”,正如 git status 会显示的那样。 将当前分支头重置为 $commit 重置索引但不重置工作树(即,保留已更改的文件但不将其标记为提交)并报告尚未更新的内容。这是默认操作。 将当前分支头重置为 $commit 重置索引和工作树。自 $commit 以来在工作树中跟踪的文件中的任何更改都将被丢弃 将当前分支头重置为 $commit 重置索引并更新工作树中与 $commit 和 HEAD 不同的文件,但保留那些在索引和工作树之间不同的文件(即尚未添加更改的文件)。如果与 $commit 和索引不同的文件具有未提交的更改,则重置操作将被中止 将当前分支头重置为 $commit 重置索引条目并更新工作树中与 $commit 和 HEAD 不同的文件。如果与 $commit 和 HEAD 不同的文件具有本地更改,则重置操作将被中止。 将当前分支头重置为 $commit 根据 $mode 可能更新索引(将其重置为 $commit 的树)和工作树。 从工作树和索引中删除文件 相当于 $git->rm($file, ['cached' => true]); 总结 'git log' 输出 抑制提交描述,仅提供提交计数摘要 显示一个或多个对象(blob、tree、tag 和提交) 将您的本地修改保存到一个新的暂存区,并运行 git reset --hard 来撤销它们 将您的本地修改保存到一个新的暂存区,并运行 git reset --hard 来撤销它们。 返回您目前拥有的暂存区 显示暂存中记录的更改,以暂存状态与其原始父状态之间的差异形式显示 从暂存列表中删除单个暂存状态 从暂存列表中删除单个暂存状态并将其应用到当前工作树状态之上 类似于 pop,但不从暂存列表中删除状态 创建并检出一个新的名为 $name 的分支,从最初创建的提交开始,将记录的更改应用到新工作树和索引中 删除所有暂存状态 创建一个暂存(它是一个常规提交对象)并返回其对象名称,而不在 ref 命名空间中存储它 返回工作树状态 返回一个标签数组 创建标签对象 删除给定名称的现有标签 验证给定标签名的GPG签名 返回树对象的内容 MIT许可证 Hayashi Kazuyuki (@kzykhys)$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->orphan('gh-pages');
选项
git clone
$git->clone(字符串 $repository, 字符串 $path = null, 数组 $options = [])
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
选项
git commit
$git->commit(字符串 $message, 数组 $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');
选项
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 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->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 init
$git->init(字符串 $path, 数组 $options = [])
$git = new PHPGit\Git();
$git->init('/path/to/repo1');
$git->init('/path/to/repo2', array('shared' => true, 'bare' => true));
选项
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']);
选项
$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(字符串 $upstream = null, 字符串 $branch = null, 数组 $options = [])
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->fetch('origin');
$git->rebase('origin/master');
选项
$git->rebase->continues()
$git->rebase->abort()
$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(字符串 $name, 字符串 $url, 数组 $options = [])
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->fetch('origin');
选项
git fetch <name>
从远程仓库导入每个标签git fetch <name>
不从远程仓库导入标签$git->remote->rename(字符串 $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(字符串 $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(字符串 $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(字符串 $name = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->prune('origin');
$git->remote->head(字符串 $name, 字符串 $branch = null)
$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(字符串 $name, 字符串 $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(字符串 $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(字符串 $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(字符串 $name, 数组 $branches)
$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(字符串 $name, 数组 $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(字符串 $name, 数组 $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(字符串 $name, 字符串 $newUrl, 字符串 $oldUrl = null, 数组 $options = [])
$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');
选项
$git->remote->url->set(字符串 $name, 字符串 $newUrl, 字符串 $oldUrl = null, 数组 $options = [])
$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');
选项
$git->remote->url->add(字符串 $name, 字符串 $newUrl, 数组 $options = [])
$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');
选项
$git->remote->url->delete(字符串 $name, 字符串 $url, 数组 $options = [])
$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');
选项
git reset
$git->reset(字符串|数组|\Traversable $paths, 字符串 $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset();
$git->reset->soft(字符串 $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->soft();
$git->reset->mixed(字符串 $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mixed();
$git->reset->hard(字符串 $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->hard();
$git->reset->merge(字符串 $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->merge();
$git->reset->keep(string $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->keep();
$git->reset->mode(string $mode, string $commit = null)
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mode('hard');
git rm
$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]);
选项
$git->rm->cached(string|array|\Traversable $file, array $options = [])
选项
git shortlog
$git->shortlog(string|array|\Traversable $commits = HEAD)
$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 show
$git->show(string $object, array $options = [])
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
echo $git->show('3ddee587e209661c8265d5bfd0df999836f6dfa2');
选项
git stash
$git->stash()
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash();
$git->stash->save(string $message = null, array $options = [])
$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 = [])
$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()
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$commit = $git->stash->create();
输出示例
877316ea6f95c43b7ccc2c2a362eeedfa78b597d
git status
$git->status(array $options = [])
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$status = $git->status();
常量
输出示例
[
'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 tag
$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');
选项
删除现有标签:$git->tag->delete(字符串|array|\Traversable $tag)
验证标签:$git->tag->verify(字符串|array|\Traversable $tag)
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'],
]
许可证
作者