名稱

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