Git
日本語 ▾ トピック ▾ 最新バージョン ▾ git-cherry 最終更新 2.0.5

名前

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 までの(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 が 3 つのコミットで構成され、メンテナがそのうちの 2 つを適用した場合、状況は次のようになります

$ 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(- でマークされている)は、origin/master の上にリベースするときに 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