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

未提交feature-23分支变更即切换至feature-24,如何拆分分支变更?

拆分跨分支未提交变更的解决方案

1. 暂存所有未提交修改

不管当前处于哪个分支,先把所有跨分支的未提交变更暂存,防止丢失:

git stash push -m "temp save all cross-branch changes"

2. 处理feature-23分支的专属修改

  • 切换到feature-23分支:
    git checkout feature-23
  • 应用暂存的全部变更:
    git stash apply
  • 通过git status查看文件,只将属于feature-23的修改添加到暂存区:
    git add <feature-23专属文件路径>
  • 提交feature-23的修改:
    git commit -m "提交feature-23分支的原始修改"
  • 将剩余的feature-24相关修改重新暂存:
    git stash push -m "暂存feature-24分支的修改"

3. 处理feature-24分支的专属修改

  • 切换到feature-24分支:
    git checkout feature-24
  • 应用暂存的feature-24专属修改:
    git stash apply
  • 提交feature-24的修改:
    git add .(或指定对应文件)
    git commit -m "提交feature-24分支的原始修改"

特殊情况:单个文件包含两个分支的混合修改

如果同一个文件里同时有两个分支的变更,需要逐块拆分:

  • 切换到对应分支后,应用暂存的变更,执行:
    git add --patch
  • 命令会逐块展示文件中的修改,输入y保留当前块到当前分支,输入n跳过该块(留到另一个分支处理)
  • 提交选中的修改后,将剩余修改重新暂存,再切换到另一分支处理剩余部分

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 10:35:21