显示 git diff,忽略文件权限更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22388811/
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 09:50:37  来源:igfitidea点击:

Show git diff, ignoring file permission changes?

gitdiffgit-diff

提问by Hommer Smith

I have run several chmodin my live server. Right now when I do a git diffthere, I see lots of old mode 100644 new mode 100755

chmod在我的实时服务器上运行了几个。现在当我在git diff那里做的时候,我看到很多old mode 100644 new mode 100755

I have also changed some files there. But I would just git diff just to show the changes on the files, ignoring the file permissions changes.

我也在那里更改了一些文件。但我只是 git diff 只是为了显示文件的更改,而忽略文件权限的更改。

How can I do that? BTW, I don't want GIT to ignore those file permissions changes. Actually I want to commit them, I just want git diff to not show them for a very specific moment.

我怎样才能做到这一点?顺便说一句,我不希望 GIT 忽略那些文件权限更改。实际上我想提交它们,我只是想让 git diff 在非常特定的时刻不显示它们。

采纳答案by Ashish Chopra

This will tell git to ignore permissions:

这将告诉 git 忽略权限:

git config core.filemode false

to filter them in result of diffbut not ignore them

根据结果​​过滤它们diff但不忽略它们

git filter-branch -f --tree-filter 'find * -type f | xargs chmod 644 ' -- --all

回答by Zed

git diff -G"."

The -Gflag filters out any file where a line that matches a regular expression has not been added or removed. In this case the regular expression provided is "."which matches any line. So the argument -G"."will filter out files where no lines have been added or removed.

-G标志过滤掉没有添加或删除匹配正则表达式的行的任何文件。在这种情况下,提供的正则表达式"."匹配任何行。因此该参数-G"."将过滤掉没有添加或删除任何行的文件。

You will need (I think) at least Git version 1.7.10 for this to work. 1.7.2 is too old, at least.

您将需要(我认为)至少 Git 版本 1.7.10 才能工作。至少 1.7.2 太旧了。