3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

git cherry-pick とは?🍒

3
Posted at

🍒 git cherry-pick とは?

他のブランチの特定のコミットだけを選んで、現在のブランチに取り込むコマンドです。

🍒サクランボを1つずつつまむように
必要なコミットだけを“選び取る”イメージです!

✅ 基本の使い方

git cherry-pick コミットID

例↓

git cherry-pick a1b2c3d

これは、a1b2c3d というコミットを 今いるブランチ に適用します。

🧠 どんなときに使う?

  • 他のブランチにある「バグ修正だけを今のブランチに反映したい」
  • 過去の特定の変更を別ブランチでも使いたい
  • developで修正した内容だけを release に持ってきたい など

📌 よくある流れ

例えば
developブランチでバグ修正をした(コミットID: abc123)
その修正だけを release ブランチにも反映したい

git checkout release
git cherry-pick abc123

🚨 注意点

  • コンフリクトが出ることがあります
    → コンフリクトを解決して git cherry-pick --continue

  • cherry-pick されたコミットは、元のコミットとは別物(新しいコミットIDになる)

  • 連続した複数のコミットを取り込みたい場合は .. を使う

git cherry-pick A..B 
# Aは含まない、Bは含む

💡補足:複数のコミットを選んで一括適用も可能

git cherry-pick commit1 commit2 commit3
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?