简体   繁体   English

抑制 git 中已删除文件的差异

[英]Suppressing diffs for deleted files in git

I want to get a quick overview of the local changes in my repository, but I don't want a diff that shows deleted files, since every single line is a minus.我想快速了解我的存储库中的本地更改,但我不想要显示已删除文件的差异,因为每一行都是减号。

Basically, I want something like 'git diff HEAD <list of modified files only>' .基本上,我想要类似'git diff HEAD <list of modified files only>' In an ideal world, it would be preceded by the list of deleted and added files, but not show the diffs within them.在理想的世界中,它前面是已删除和添加的文件列表,但不显示其中的差异。

I was most of the way through writing a utility that does this:我大部分时间都在编写一个执行此操作的实用程序:

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

when I wondered if there was some git-y way to do it instead.当我想知道是否有一些 git-y 方法来代替时。 Is there a flag I'm missing?有没有我失踪的旗帜? I'd love to preserve the color output, too.我也很想保留颜色输出。

In Git versions 1.8.5 and newer, you can do this using the --diff-filter option and specifying "d" (lowercase) to tell it to exclude deleted files.在 Git 版本 1.8.5 和更新版本中,您可以使用--diff-filter选项并指定“d”(小写)来告诉它排除已删除的文件。

$ git diff --diff-filter=d

In Git versions older than 1.8.5, you can do this with the --diff-filter option and specifying all but the "D" (deleted) criteria:在 1.8.5 之前的 Git 版本中,您可以使用--diff-filter选项并指定除“D”(已删除)条件之外的所有条件:

$ git diff --diff-filter=ACMRTUXB

git diff -D (or equivalently git diff --irreversible-delete ) will omit the diff body for deleted files. git diff -D (或等效的git diff --irreversible-delete )将省略已删除文件的差异正文。 I don't think there's an equivalent for added files.我不认为添加文件有等价物。

张贴几乎相同的答案Dan Moulding ,但你可能要指定你想要的东西来展示,并隐藏删除的文件将是:

git diff --diff-filter=d

You also may use -M which try to find files that was moved您也可以使用 -M 尝试查找已移动的文件

git diff -M -D 

more may get more info with: git diff --help (option -B also could be interesting) more 可以通过以下方式获得更多信息: git diff --help (选项 -B 也可能很有趣)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM