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

如何用Git Diff排除基准分支变更文件,仅展示共同祖先差异?

解决方案

直接用以下命令就能实现你的需求:

git diff --name-only $(git merge-base other-branch main) other-branch

命令解释

  • git merge-base other-branch main:自动定位两个分支的共同祖先提交(即你的提交A),输出该提交的哈希值。
  • 将这个哈希值作为对比起点,和other-branch执行git diff --name-only,就能只显示other-branch相对于共同祖先修改过的文件,也就是你需要的other.txt,完全排除main分支单独修改的main.txt。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 02:15:36