如何用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
相关产品推荐
相关产品推荐

