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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3692152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:33:52  来源:igfitidea点击:

Suppressing diffs for deleted files in git

gitshellfile-diffs

提问by Alex Feinman

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>'. In an ideal world, it would be preceded by the list of deleted and added files, but not show the diffs within them.

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

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. Is there a flag I'm missing? I'd love to preserve the color output, too.

当我想知道是否有一些 git-y 方法来代替时。有没有我遗漏的旗帜?我也很想保留颜色输出。

回答by Dan Moulding

In Git versions 1.8.5 and newer, you can do this using the --diff-filteroption 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-filteroption and specifying all but the "D" (deleted) criteria:

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

$ git diff --diff-filter=ACMRTUXB

回答by nktssh

Almost same answer as posted Dan Moulding, but you probably want to specify what you don'twant to show, and for hide deleted files it will be:

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

git diff --diff-filter=d

回答by Max Nanasy

git diff (-D|--irreversible-delete)will omit the diff body for deleted files. I don't think there's an equivalent for added files.

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

回答by Sérgio

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 也可能很有趣)