You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git特性分支拖太久,如何拆分提交至新分支?

Git分支调整解决方案
  • 创建新分支保存误提交的代码
    基于当前feature/v3.1.1的HEAD创建新分支,暂存133b607到HEAD的所有提交:

    git checkout -b feature/new-feature
    
  • 将feature/v3.1.1重置到正确的最终提交
    切回目标分支,通过硬重置将分支指向e8c4651(该分支应有的最后一次提交):

    git checkout feature/v3.1.1
    git reset --hard e8c4651
    
  • 合并feature/v3.1.1到master分支
    切换到master,合并调整后的特性分支:

    git checkout master
    git merge feature/v3.1.1
    
  • 让新分支基于合并后的master重新定位
    切回新分支,通过rebase让所有误提交的代码基于最新的master:

    git checkout feature/new-feature
    git rebase master
    

以上操作完成后,feature/v3.1.1会停在e8c4651,新分支包含原本误提交的12次提交,且完全基于合并后的master分支,所有提交均被保留。

内容的提问来源于stack exchange,提问作者dpm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 11:52:45