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

我无意中更改了整个树的权限,并提交了该更改以及其他内容更改。

我使用类似于:

Tar-czf 部署.tar git diff --name-only v1 v2

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

有没有一种方法,我可以告诉 git diff忽略那些只有权限改变的文件?

49762 次浏览

This will tell git to ignore permissions:

git config core.filemode false

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.

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

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, i.e.

cp -pr ~/repo.git ~/repo-orig.git

or similar, in case you need to re-try.

Enjoy!

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.

So: git diff -G.