76

我想快速了解我的存储库中的本地更改,但我不想要显示已删除文件的差异,因为每一行都是减号。

基本上,我想要类似'git diff HEAD <list of modified files only>'. 在理想情况下,它前面会显示已删除和添加的文件列表,但不会显示其中的差异。

我主要是通过编写一个执行此操作的实用程序:

git diff HEAD `git status | grep modified | cut -d : -f 2`

当我想知道是否有一些 git-y 方式来代替它时。有没有我失踪的标志?我也想保留颜色输出。

4

5 回答 5

117

在 Git 版本 1.8.5 和更高版本中,您可以使用该--diff-filter选项并指定“d”(小写)来告诉它排除已删除的文件。

$ git diff --diff-filter=d

在 1.8.5 之前的 Git 版本中,您可以使用--diff-filter选项并指定除“D”(已删除)之外的所有条件:

$ git diff --diff-filter=ACMRTUXB
于 2010-09-11T18:57:00.240 回答
30

git diff -D(或等效地git diff --irreversible-delete)将省略已删除文件的差异主体。我认为添加的文件没有等价物。

于 2013-03-13T01:06:10.033 回答
24

几乎与所发布的答案相同Dan Moulding,但您可能想要指定您不想显示的内容,并且对于隐藏已删除的文件,它将是:

git diff --diff-filter=d
于 2017-01-20T21:32:08.420 回答
2

您也可以使用 -M 来尝试查找已移动的文件

git diff -M -D 

more 可以通过以下方式获得更多信息: git diff --help (选项 -B 也可能很有趣)

于 2016-11-10T07:12:18.140 回答
0

在上一个答案之上,我想添加文档中关于 git 版本 2.33.0 的内容

--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
       Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown (X), or have had their
       pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in
       the comparison; if there is no file that matches other criteria, nothing is selected.

       Also, these upper-case letters can be downcased to exclude. E.g.  --diff-filter=ad excludes added and deleted paths.

       Note that not all diffs can feature all types. For instance, diffs from the index to the working tree can never have Added entries (because the set of paths included in the diff is limited by what is in the index).
       Similarly, copied and renamed entries cannot appear if detection for those types is disabled.
于 2021-09-16T22:22:08.147 回答