git cherry-pick
git
書き方
git cherry-pick [-x] <commit>...他のブランチのコミット一つを今のブランチへ複製します。新しいハッシュになるため、後でそのブランチをmergeすると同じ変更が二度現れることがあります。
よく使うオプション
| オプション | 意味 |
|---|---|
| -x | note the original hash in the new message |
| -n | apply and stage without committing |
| -e | edit the message |
| -m <parent> | pick a merge commit, choosing a side |
| <a>..<b> | a range; a itself is not included |
| --continue | go on after a conflict |
| --abort | undo the whole pick |
例
git cherry-pick a1b2c3dcopies that commit onto the current branch with a new hash
git cherry-pick -x a1b2c3dsame, with the source hash recorded in the message
git cherry-pick a1b2c3d^..d4e5f6acopies 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