git 删除branch某些commit

git rebase --onto 删除commit

Git 管理代码,如果某个分支commit 了多次提交,但是发现中间一些commit提交想删除它。怎么操作呢?看官方例子。

备注:topicA 代表分支名称

      topicA~5  代表改分支从HEAD向后数5个,这里就是F commit

topicA~3  代表改分支从HEAD向后数3个,这里就是H commit

git rebase --onto topicA~5 topicA~3 topicA

所以上面命令是把F到H(不包含它)的commit 删除。

例子

git init ./

touch.exe file1.c && git add file1.c && git commit -m "Add file1.c"

touch.exe file2.c && git add file2.c && git commit -m "Add file2.c"

touch.exe file3.c && git add file3.c && git commit -m "Add file3.c"

touch.exe file4.c && git add file4.c && git commit -m "Add file4.c"

touch.exe file5.c && git add file5.c && git commit -m "Add file5.c"

touch.exe file6.c && git add file6.c && git commit -m "Add file6.c"

执行Git log

commit 历史如下

执行 git rebase --onto master~5 master~3 master

commit 历史如下

提示: 可以直接指定具体的 commit ID 去删除

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值