Can I make git diff ignore permission changes

GitDiff

Git Problem Overview


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

I use something like :

tar -czf deploy.tar 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.

Is there a way that I could tell git diff to ignore those files which only has the permissions changed?

Git Solutions


Solution 1 - Git

This will tell git to ignore permissions:

git config core.filemode false

Solution 2 - Git

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.

Solution 3 - Git

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!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCesarView Question on Stackoverflow
Solution 1 - GitDaniel StutzbachView Answer on Stackoverflow
Solution 2 - GitlazysoundsystemView Answer on Stackoverflow
Solution 3 - GitAlan ThompsonView Answer on Stackoverflow