Git问题排查:将feature2独有提交迁移至feature1时混入develop提交
解决Git Rebase --onto误引入远程Develop提交的问题
问题场景
- 分支关系:feature1基于旧版本的develop,feature2基于新版本的远程develop
- 需求:仅将feature2中不属于develop的提交迁移到feature1上
- 执行命令:
git rebase --onto feature1 develop feature2 - 异常现象:远程develop的新提交也被应用到了feature1上
问题原因
本地develop分支未与远程develop同步,导致本地develop的提交记录落后于feature2基于的远程版本。执行git rebase --onto feature1 develop feature2时,Git会把feature2中所有在本地develop之后的提交迁移到feature1上——由于本地develop没同步,Git误将远程develop的新提交判定为feature2独有的内容,最终把这些不属于feature2的提交也带了过去。
正确操作步骤
- 先同步本地develop到远程版本:
git checkout develop git pull origin develop - 重新执行rebase命令,此时Git能准确识别feature2的独有提交:
git rebase --onto feature1 develop feature2 - 若需要将feature1更新为迁移后的结果,可执行:
git checkout feature1 git merge feature2
内容的提问来源于stack exchange,提问作者Abhilash
相关产品推荐
相关产品推荐

