名称

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>

不报告直到(包括)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 分支 rebase 到 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 指定为限制,您可以避免列出 basetopic 之间的提交

$ git cherry origin/master topic base
- cccc000... commit C
+ bbbb000... commit B
- aaaa000... commit A

另请参阅

GIT

Git[1] 套件的一部分

scroll-to-top