Suppressing diffs for deleted files in git

房东的猫 提交于 2020-01-11 15:06:07

问题


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.

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.


回答1:


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 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:

$ git diff --diff-filter=ACMRTUXB



回答2:


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




回答3:


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

git diff --diff-filter=d



回答4:


You also may use -M which try to find files that was moved

git diff -M -D 

more may get more info with: git diff --help (option -B also could be interesting)



来源:https://stackoverflow.com/questions/3692152/suppressing-diffs-for-deleted-files-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!