git cherry-pick

git

書き方

git cherry-pick [-x] <commit>...

他のブランチのコミット一つを今のブランチへ複製します。新しいハッシュになるため、後でそのブランチをmergeすると同じ変更が二度現れることがあります。

よく使うオプション

オプション意味
-xnote the original hash in the new message
-napply and stage without committing
-eedit the message
-m <parent>pick a merge commit, choosing a side
<a>..<b>a range; a itself is not included
--continuego on after a conflict
--abortundo the whole pick

git cherry-pick a1b2c3d

copies that commit onto the current branch with a new hash

git cherry-pick -x a1b2c3d

same, with the source hash recorded in the message

git cherry-pick a1b2c3d^..d4e5f6a

copies a range, this time including a1b2c3d

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git cherry-pick は何をしますか。

他のブランチのコミット一つを今のブランチへ複製します。新しいハッシュになるため、後でそのブランチをmergeすると同じ変更が二度現れることがあります。

Q. どう打ちますか。

git cherry-pick [-x] <commit>... — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-cherry-pick