實際問題:
在本地 master 分支上作了一個commit ( 38361a68138140827b31b72f8bbfd88b3705d77a ) , 如何把它放到 本地 old_cc 分支上?
辦法之一: 使用 cherry-pick. 根據git 文檔:git
Apply the changes introduced by some existing commits
就是對已經存在的commit 進行apply (能夠理解爲再次提交)
簡單用法:web
git cherry-pick <commit id>
例如:
$ git checkout old_cc
$ git cherry-pick 38361a68 # 這個 38361a68 號碼,位於:vim
$ git log
commit 38361a68138140827b31b72f8bbfd88b3705d77a
Author: Siwei Shen <siwei.shen@focusbeijing.com>
Date: Sat Dec 10 00:09:44 2011 +0800
1. 若是順利,就會正常提交。結果:app
Finished one cherry-pick.
# On branch old_cc
# Your branch is ahead of 'origin/old_cc' by 3 commits.
2. 若是在cherry-pick 的過程當中出現了衝突spa
Automatic cherry-pick failed. After resolving the conflicts,
mark the corrected paths with 'git add <paths>' or 'git rm <paths>'
and commit the result with:
git commit -c 15a2b6c61927e5aed6718de89ad9dafba939a90b
就跟普通的衝突同樣,手工解決:
2.1 $ git status # 看哪些文件出現衝突orm
both modified: app/models/user.rb
2.2 $ vim app/models/user.rb # 手動解決它。
2.3 $ git add app/models/user.rb
2.4 git commit -c <新的commit號碼>
文檔