# [Git] `cherry-pick` 撿其他 branch commit 貼到目前 branch 上 ###### tags: `Git` ## 情境 有時候只想要其他 branch 上的某幾個 commit 時該怎麼做呢?  比如說現在有兩個 branches(master and dog),但是我只想要 dog 第二個 commit `add dogs` ## 撿特定 commit 到目前 branch 的好幫手 ``` git cherry-pick some commits / commit ``` 下完這個指令後,Git 就會把指定的 commits 加到當前 HEAD 之後了。如果是使用 Sourcetree 更簡單,一樣先移動到目標 branch,選取想要的 commit 後點選右鍵叫出選單後選擇 Cherry pick 就可以了。   ## 如果發生衝突呢? 別擔心,就直接解衝突就好了,解完記得將改動推入 Staging Area (暫存區)就是下完 `git add` 之後會跑到的地方,之後再下 `git cherry-pick --continue`,填寫完 commit message 就完成了。 如果想要全部重來的話,下 `git cherry-pick --abort` 便可以放棄這次的 `cherry-pick`。 ## 參考資料 1. [【狀況題】如果你只想要某個分支的某幾個 Commit?](https://gitbook.tw/chapters/faq/cherry-pick) 2. [Cherry-Pick 版本衝突](https://zlargon.gitbooks.io/git-tutorial/content/patch/cherry_pick_conflict.html)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up