git cherry
git-cherry
名称
git-cherry - 查找尚未应用于上游的提交
概要
git cherry [-v] [<upstream> [<head> [<limit>]]]
描述
确定在<head>..<upstream>那里的提交是否有与<limit>..<head>范围内的提交相同。
删除空格和行号后,基于 diff 等同性测试。因此, git-cherry 可以检测提交何时通过 git-cherry-pick [1],git-am [1]或git-rebase [1] 被“复制”。
在<limit>..<head>输出每个提交的 SHA1 ,前缀-为<upstream>(<上游>)中的等价提交,以及不提交+的提交。
选项
-v
显示 SHA1 旁边的提交主题。
<upstream>
上游分支来搜索等效提交。默认为 HEAD 的上游分支。
<head>
工作分部;默认为 HEAD。
<limit>
不要报告提交到(包括)限制。
示例
补丁工作流程
git-cherry 经常用于基于补丁的工作流程(请参阅gitworkflows [7])以确定上游维护人员是否应用了一系列补丁。在这样的工作流程中,您可以创建并发送如下主题分支:
$ git checkout -b topic origin/master
# work and create some commits
$ git format-patch origin/master
$ git send-email ... 00*
稍后,您可以通过说(仍在topic
)来查看您的更改是否已应用:
$ git fetch # update your notion of origin/master
$ git cherry -v
具体的例子
在主题由三个提交组成的情况下,维护者应用其中两个提交时,情况可能如下所示:
$ git log --graph --oneline --decorate --boundary origin/master...topic
* 7654321 (origin/master) upstream tip commit
[... snip some other commits ...]
* cccc111 cherry-pick of C
* aaaa111 cherry-pick of A
[... snip a lot more that has happened ...]
| * cccc000 (topic) commit C
| * bbbb000 commit B
| * aaaa000 commit A
|/
o 1234567 branch point
在这种情况下,git-cherry 会显示一个尚未应用的简要摘要:
$ git cherry origin/master topic
- cccc000... commit C
+ bbbb000... commit B
- aaaa000... commit A
在这里,我们看到提交 A 和 C(标记为-
)可以从您的topic
分支中删除,当您重新绑定它origin/master
时,提交 B(标记为+
)仍然需要保留,以便它将被发送以应用到origin/master
。
使用限制
如果您的主题基于其他不在上游的工作,则可选<limit>非常有用。在前面的例子中展开,这可能看起来像:
$ git log --graph --oneline --decorate --boundary origin/master...topic
* 7654321 (origin/master) upstream tip commit
[... snip some other commits ...]
* cccc111 cherry-pick of C
* aaaa111 cherry-pick of A
[... snip a lot more that has happened ...]
| * cccc000 (topic) commit C
| * bbbb000 commit B
| * aaaa000 commit A
| * 0000fff (base) unpublished stuff F
[... snip ...]
| * 0000aaa unpublished stuff A
|/
o 1234567 merge-base between upstream and topic
通过指定base
限制,您可以避免列出base
和topic
之间的提交:
$ git cherry origin/master topic base
- cccc000... commit C
+ bbbb000... commit B
- aaaa000... commit A