首頁·終端機命令
廣告

加密貨幣交易所註冊優惠

只要註冊就能領取的優惠。條件皆依各交易所公告原樣列出。

git cherry-pick

git

用法

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

把某一個提交以新的雜湊複製到目前分支;之後再合併那個分支時,同一處改動可能出現兩次。

常用選項

選項含義
-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 不是一回事。

常見問題

Qgit cherry-pick 是做什麼的?

把某一個提交以新的雜湊複製到目前分支;之後再合併那個分支時,同一處改動可能出現兩次。

Q怎麼寫?

git cherry-pick [-x] <commit>... —— 方括號表示可以省略的部分。

Q值得記的選項有幾個?

這裡列了 7 個,完整列表在 man git。這條命令屬於git。

相關命令

man 手冊: man git-cherry-pick