码迷,mamicode.com
首页 > 其他好文 > 详细

git cherry-pick简介

时间:2016-01-30 13:16:40      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

转载: http://blog.csdn.net/hudashi/article/details/7669462

 

git cherry-pick用于把另一个本地分支的commit修改应用到当前分支。
 
实际问题 
    在本地 master 分支上做了一个commit ( 38361a68138140827b31b72f8bbfd88b3705d77a ) , 如何把它放到 本地 old_cc 分支上? 
办法之一: 使用 cherry-pick.  根据git 文档:
Apply the changes introduced by some existing commits 
就是对已经存在的commit 进行apply (可以理解为再次提交)
 
简单用法
git cherry-pick <commit id>
例如:
$ git checkout old_cc
git cherry-pick 38361a68
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

就跟普通的冲突一样,手工解决:
执行git status 看哪些文件出现冲突
$ git status 
both modified:      app/models/user.rb 
接着手动解决冲突的文件,然后通过git add把改到添加到索引,最后执行git commit提交修改。
$ vim app/models/user.rb   
$ git add app/models/user.rb
git commit -c <原commit号>
 
 

git cherry-pick简介

标签:

原文地址:http://www.cnblogs.com/pengdonglin137/p/5170630.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!