Git で fork 元のリポジトリの変更を cherry-pick して fork 先に反映するには、以下の手順で実施できます。
Git で別リポジトリのコミットを cherry-pick するには、以下の手順で行います。
- cherry-pick したいコミットのSHAを確認
cherry-pick 元のリポジトリで
git log などを使い、対象コミットID(ハッシュ値)を調べます。
- cherry-pick 先のリポジトリにリモートを追加(または一時的に fetch)
例:
git remote add upstream <URL>
または、fetch だけする場合: git fetch <URL> <branch>
後者の場合、次項目
3 を行わない
- コミットを fetch する
例: git fetch
upstream
- cherry-pick を実行したいブランチをチェックアウト
例:
git checkout your-branch
- cherry-pick コマンドを実行
例:
git cherry-pick <コミットID>
- git リモートサーバーへ push
例: git
push origin <自分の作業ブランチ>
- 不要になったリモートを削除(必要に応じて)
例: git remote remove
upstream
具体例:
# 1. cherry-pick 元のリポジトリでコミットSHAを確認
$ git log
# 2. cherry-pick 先のリポジトリでリモート追加
$ git remote add temp-origin https://github.com/example/other-repo.git
# 3. fetchする
$ git fetch temp-origin main
# 4. cherry-pick したいブランチに移動
$ git checkout your-branch
# 5. cherry-pick 実行
$ git cherry-pick <コミットSHA>
# 6. git リモートサーバーへ push
$ git push origin <自分の作業ブランチ>
# 7. リモート削除(任意)
$ git remote remove temp-origin
本ページの情報は、特記無い限り下記 MIT ライセンスで提供されます。
The MIT License (MIT)
Copyright 2025 Kinoshita Hidetoshi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.