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

能否通过交互式Git Rebase实现分支重复提交的合并目标?

问题:通过交互式Rebase实现指定分支状态

当前分支状态

main-branch 的提交历史:

main-branch
* somehash001 (与下方提交内容完全一致)
* somehash002
...

feature-branch 的提交历史:

feature-branch
* somehash003
* somehash001 (与上方提交内容完全一致)
...

期望目标状态

希望将 feature-branch 基于 main-branch 执行 Rebase 后,仅保留一个合并提交:

feature-branch
* somehash004 (合并somehash001与somehash003的提交)
...

已尝试的操作及遇到的问题

执行命令:git rebase --i main-branch
编写的交互式Rebase指令:

p somehash003 ...
s somehash001 ...

最终得到的分支状态不符合预期:

feature-branch
* somehash004 (已正确合并somehash001与somehash003)
* somehash001
...

推测原因是:feature-branch上的somehash001被合并后,main-branch上的同名提交仍被保留,且因该提交与待合并提交内容完全一致,无法直接跳过。目前已通过临时重置操作解决问题,但想咨询:能否从当前起始状态通过交互式Rebase实现上述目标状态?应使用哪些指令?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 01:20:10