git diff:仅显示两个提交中存在的文件 [英] git diff: Show only diff for files that exist in both commits

查看:100
本文介绍了git diff:仅显示两个提交中存在的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 git diff 在两个提交之间获取差异,但只显示两个提交中存在的文件的差异?



我有一个几个星期前创建的分支,现在我们的主代码已经与之分离了很多。因此,如果我在当前的HEAD和旧分支的尖端之间进行差异化处理,我会得到几十个已更改的文件,但它们大多只是噪音。



什么我真的想看到的是一个差异,只显示两个分支中存在的文件。我知道一种方法是在当前HEAD的顶部挑选另一个分支的提交,但是有没有办法使用 git diff 来完成?

解决方案

以下内容是否符合您的要求?

  git diff --diff-filter = M commitA commitB 



<$> <$对于 - diff-filter ,c $ c> M 选项仅包含似乎在两次提交之间修改的文件 - 存在于一个分支或另一个分支中时,可以选择 A (已添加)或 D (已删除)。 。

你可以看到用这些字母代码选择哪些文件:

  git diff --name-status commitA commitB 

...还有更多信息关于 git diff 文档中的所有内容


Is there a way to use git diff to get a diff between two commits, but only show the diff for the files that exist in both commits?

I have a branch I created a couple weeks ago, and our main code has diverged quite a bit from it by now. As a result, if I do a diff between my current HEAD and the tip of the old branch, I get dozens of changed files, but it's mostly just noise.

What I really want to see is a diff that shows only the files that exist in both branches. I know one way to do this would be to cherry-pick the other branch's commits on top of the current HEAD, but is there a way to do it just using git diff?

解决方案

Does the following do what you want?

git diff --diff-filter=M commitA commitB

The M option to --diff-filter says only to include files that appear to be modified between the two commits - ones that only exist in one branch or the other would be selected with A ("added") or D ("deleted").

You can see which files would be selected with these letter codes by doing:

git diff --name-status commitA commitB

... and there's more information about all of that in the git diff documentation.

这篇关于git diff:仅显示两个提交中存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆