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

如何让PR仅展示feature分支相对main分支的独有变更?

解决PR显示冗余main分支变更的问题

问题根源是你用了squash merge将main合并到feature分支,这种操作会把main的变更打包成一个全新提交加到feature上,导致feature和main的提交历史失去线性关联,PR的差异对比会误把这些squash进来的内容当成feature的独有变更。

用以下步骤修复:

  • 先确保本地main分支是最新状态:
    git checkout main
    git pull origin main
    
  • 切换到你的feature分支,执行rebase操作(把feature的提交重新应用到main的最新版本上):
    git checkout feature
    git rebase main
    
  • 如果遇到冲突,手动修改冲突文件,然后执行:
    git add <冲突文件>
    git rebase --continue
    
    重复这个过程直到rebase完成。
  • 因为rebase修改了提交历史,需要强制推送到远程feature分支:
    git push -f origin feature
    
  • 回到PR页面刷新,此时PR会只展示feature分支相对于main的独有变更。

注意:如果有其他同事也在这个feature分支上协作,强制推送会覆盖他们的本地提交,操作前一定要提前沟通确认。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 04:40:24