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     # 这个 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号码>




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值