git cherry-pick可以選擇某一個分支中的一個或幾個commit(s)來進行操作。例如,假設我們有個穩定版本的分支,叫v2.0,另外還有個開發版本的分支v3.0,我們不能直接把兩個分支合並,這樣會導致穩定版本混亂,但是又想增加一個v3.0中的功能到v2.0中,這里就可以使用cherry-pick了。
就是對已經存在的commit 進行 再次提交;
簡單用法:
git cherry-pick <commit id>
注意:當執行完 cherry-pick 以后,將會 生成一個新的提交;這個新的提交的哈希值和原來的不同,但標識名 一樣;
例如:
$ git checkout old_cc
$ git cherry-pick 38361a68 # 這個 38361a68 號碼,位於:
$ git log
commit 38361a68138140827b31b72f8bbfd88b3705d77a
Author: Siwei Shen <siwei.shen@focusbeijing.com>
Date: Sat Dec 10 00:09:44 2011 +0800
1. 如果順利,就會正常提交。結果:
Finished one cherry-pick.
# On branch old_cc
# Your branch is ahead of 'origin/old_cc' by 3 commits.
2. 如果在cherry-pick 的過程中出現了沖突
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 # 看哪些文件出現沖突
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號碼>
---------------------
作者:wh_19910525
來源:CSDN
原文:https://blog.csdn.net/wh_19910525/article/details/7554430
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!