'git diff':仅显示两次提交中存在的文件的diff [英] 'git diff': Show only diff for files that exist in both commits
问题描述
是否可以使用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?
我有几个星期前创建的分支,到目前为止,我们的主要代码与之大相径庭.结果,如果我在当前的HEAD和旧分支的尖端之间做一个区分,我会得到几十个已更改的文件,但这主要只是杂音.
I have a branch I created a couple of 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.
我真的很想看到一个仅显示两个分支中都存在的文件的差异.我知道一种方法是在当前HEAD的顶部樱桃选择其他分支的提交,但是有没有办法仅使用git diff
来做到这一点?
I really want to see 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
?
推荐答案
以下内容可能会满足您的要求:
The following may do what you want:
git diff --diff-filter=M commitA commitB
--diff-filter
的M
选项仅表示包括在两次提交之间被修改的文件-仅存在于一个分支或另一个分支中的文件将使用A
(添加")或D
(已删除").
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
...,有关更多信息,请参见 git diff
文档.
... and there's more information about all of that in the git diff
documentation.
这篇关于'git diff':仅显示两次提交中存在的文件的diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!