Git基础操作:合并某个分支的一个commit到另一个分支

有的时候不小心在错误的分支A上开发了一点代码,也已经提交了,这个时候如果想把这部分代码移到正确的分支B上可以如下操作

  1. 使用git log命令找到错误提交的那次commitid
git log
commit 8b19200eed045d5bef5b304c30eb76d74f3943ea (HEAD -> A, origin/A)
Author: alioo <xxx@yyy.com>
Date:   2021-03-08T21:45:40+08:00

    取消没有必要的RecommendException
  1. checkout到分支B之后,使用cherry-pick命令进行merge
git checkout B
Switched to branch 'B'
Your branch is up to date with 'origin/B'.

 git cherry-pick 8b19200eed045d5bef5b304c30eb76d74f3943ea
[A b2da47b48] 取消没有必要的RecommendException
 Date: Mon Mar 8 21:45:40 2021 +0800
 1 file changed, 4 insertions(+), 2 deletions(-)
 
git status
On branch B
Your branch is ahead of 'B' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

git push
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (14/14), 1.04 KiB | 353.00 KiB/s, done.
Total 14 (delta 6), reused 0 (delta 0)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值