git cherry-pick
git
用法
git cherry-pick [-x] <commit>...把某一個提交以新的雜湊複製到目前分支;之後再合併那個分支時,同一處改動可能出現兩次。
常用選項
| 選項 | 含義 |
|---|---|
| -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 是做什麼的?
把某一個提交以新的雜湊複製到目前分支;之後再合併那個分支時,同一處改動可能出現兩次。
Q. 怎麼寫?
git cherry-pick [-x] <commit>... —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-cherry-pick