能否通过交互式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
相关产品推荐
相关产品推荐

