名称

git-cherry - 查找尚未应用于上游的提交

概要

git cherry [-v] [<upstream> [<head> [<limit>]]]

描述

确定 <head>..<upstream> 中是否存在与 <limit>..<head> 范围内的提交等效的提交。

等效性测试基于差异,在删除空格和行号之后。 因此,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

在这里,我们看到当您将 topic 分支变基到 origin/master 之上时,可以从您的 topic 分支中删除提交 A 和 C(标记为 -),而提交 B(标记为 +)仍然需要保留,以便将其发送到 origin/master 应用。

使用 limit

在您的主题基于上游中没有的其他工作的情况下,可选的 <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 指定为 limit,您可以避免列出 basetopic 之间的提交

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

GIT

属于 git[1] 套件的一部分

scroll-to-top