Git

名稱

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

具體範例

在 topic 包含三個提交,而維護者套用了其中兩個提交的情況下,情況可能如下所示

$ 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

在這裡,我們看到當你在 origin/master 之上重新設定分支時,提交 A 和 C(標記為 -)可以從你的 topic 分支中刪除,而提交 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