我可以让 git diff 忽略权限更改吗

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

Can I make git diff ignore permission changes

gitdiff

提问by Cesar

I unadvertedly change the permissions of my entire tree and commit that change alone with other content changes.

我无意中更改了整个树的权限,并将该更改与其他内容更改一起提交。

I use something like :

我使用类似的东西:

tar -czf deploy.tar git diff --name-only v1 v2

to generate a tar with the modified files between two tags, the problem is that now because of the permissions change almost all my tree is listed as modified.

要在两个标签之间生成带有修改文件的 tar,问题是现在由于权限更改,几乎所有我的树都被列为已修改。

Is there a way that i could tell git diffto ignore those files which only has the permissions changed?

有没有办法让我git diff忽略那些只更改了权限的文件?

采纳答案by lazysoundsystem

This is an old question, and the answer is already in the comments but:

这是一个老问题,答案已经在评论中,但是:

Use the -G<regex>option ("Look for differences whose patch text contains added/removed lines that match <regex>.") searching for any changes at all - i.e. .. Permissions-only changes don't match this, so they are ignored.

使用-G<regex>选项(“查找其补丁文本包含匹配的添加/删除行的差异<regex>。”)搜索任何更改 - 即.。仅权限更改与此不匹配,因此它们将被忽略。

So: git diff -G.

所以: git diff -G.

回答by Daniel Stutzbach

This will tell git to ignore permissions:

这将告诉 git 忽略权限:

git config core.filemode false

回答by Alan Thompson

I had this problem after intentionally removing the execute permission from source code files (~26K files). Then, git diff says that all files have changed! The answer with core.filemode does not help me since that only affects diffs against your working dir, not diffs against 2 commits in the repo.

在故意从源代码文件(~26K 文件)中删除执行权限后,我遇到了这个问题。然后, git diff 说所有文件都已更改!core.filemode 的答案对我没有帮助,因为它只影响对你的工作目录的差异,而不是对 repo 中的 2 个提交的差异。

The answer was to use the (big scary) filter-branch command. In particular, all you need to type is:

答案是使用(可怕的) filter-branch 命令。特别是,您只需要输入:

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

from the root of your working dir. Of course, be sure to make a copy of your repo first (cp -pr ~/repo.git ~/repo-orig.git or similar), in case you need to re-try.

从您的工作目录的根目录。当然,一定要先复制一份你的 repo(cp -pr ~/repo.git ~/repo-orig.git 或类似的),以防你需要重试。

Enjoy!

享受!