Show git diff, ignoring file permission changes?
Asked Answered
P

2

41

I have run several chmod in my live server. Right now when I do a git diff there, I see lots of 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.

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.

Pi answered 13/3, 2014 at 19:20 Comment(1)
Please could you mark the other answer, below, as correct, instead of the one that is currently marked as correct? The one that is currently marked as correct was clearly well-intended, but does something that is different to what was asked for ("I just want git diff to not show them for a very specific moment.") and that is potentially destructive. Thanks.Eucken
I
23

This will tell git to ignore permissions:

git config core.filemode false

to filter them in result of diff but not ignore them

git filter-branch -f --tree-filter 'find * -type f | xargs chmod 644 ' -- --all
Idou answered 13/3, 2014 at 19:29 Comment(8)
I don't want GIT to ignore my file permission changes. I want git diff to not show them...Pi
are one of these actually a solution? I think I am in the same situation and it seems like both of these answers ignore the permissions with relevance to the commit, not just to see the files that were changed.Portiaportico
@HommerSmith, This should work for your need: git -c core.fileMode=false diff Courtesy: https://mcmap.net/q/11491/-how-do-i-make-git-ignore-file-mode-chmod-changesWhittemore
Isn't a filter-branch somehow heavy-handed, since it changes history? I hope beginners won't blindly break a project history with that. In the meantime, the asker added: "Actually I want to commit them, I just want git diff to not show them for a very specific moment.", so a filter-branch is probably not what's asked for.Frog
The OP doesn't want git to ignore mode changes, they just don't want to see them in diff. Look at Zed's answer as the correct one.Proximate
In my testing, git config core.filemode false does not seem to affect the output from git diff when two branches (containing mode changes but nothing else) are diff'ed. This was with git 2.17.0 on Mac OS, with the local repo on an ExFAT filesystem. For some reason git diff always shows the mode changes, regardless of what core.filemode is set to.Gorilla
@Gorilla Not my experience with 2.17.1 on Ubuntu. There, Zed's hack below shows the mode changes—but only on files that do differ otherwise—and the core.fileMode=false option is identical except for not showing the filemode change. I don't know whether git cares about case in the config options, though...Ashore
I downvoted because that second command literally changes the permissions on all files. That's incredibly dangerous for someone who might blindly copy and paste that command and wonder what the heck happened.Mortimer
R
97
git diff -G"."

The -G flag 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.

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

Reform answered 13/3, 2014 at 19:30 Comment(10)
1.7.9.5 Also appears to be too old :(Proof
The period at the end of "-G." is significant, in case anyone is as dense as I was and thought that was the end of a sentence. -G looks for a regex ("." here) in added/removed lines.Laski
Please note that this is actually a nice hack. By default, git would show permission changes, and this command is asking git to show only change that affects at least one line in the file. This does the job since permission-only change do not affect any line. How about binary files, and what happens when a file has changes in both content and permission, though?Frog
I'm surprised this didn't get more upvotes. Does the trick for me, since core.fileMode does not affect change in write permissions.Bortman
I think this will also hide deletions.Proximate
This works great thank you. One issue I have is that I get messages of the type "/tmp/8ccRcc_ilsp.doc is not a Word Document." I am guessing this is due to binary files in my repo. Can you shed any light on this? Have you encountered this issue before?Clare
I realised that this is a Git for Windows issue. Solution in this SO post.Clare
@FrankRobertAnderson I'm using it right now, and it is not hiding the deletionsAshore
For some reason this solution is incompatible with --ignore-space-at-eol. If I git diff -G. revA..revB then I suppress reporting of mode changes, as desired, but I do see line-ending changes. If I add --ignore-space-at-eol I suppress line-ending changes, as desired, but the mode changes come back. Why would that be? I want to suppress both.Jerome
This also hides empty files (obviously).Subirrigate
I
23

This will tell git to ignore permissions:

git config core.filemode false

to filter them in result of diff but not ignore them

git filter-branch -f --tree-filter 'find * -type f | xargs chmod 644 ' -- --all
Idou answered 13/3, 2014 at 19:29 Comment(8)
I don't want GIT to ignore my file permission changes. I want git diff to not show them...Pi
are one of these actually a solution? I think I am in the same situation and it seems like both of these answers ignore the permissions with relevance to the commit, not just to see the files that were changed.Portiaportico
@HommerSmith, This should work for your need: git -c core.fileMode=false diff Courtesy: https://mcmap.net/q/11491/-how-do-i-make-git-ignore-file-mode-chmod-changesWhittemore
Isn't a filter-branch somehow heavy-handed, since it changes history? I hope beginners won't blindly break a project history with that. In the meantime, the asker added: "Actually I want to commit them, I just want git diff to not show them for a very specific moment.", so a filter-branch is probably not what's asked for.Frog
The OP doesn't want git to ignore mode changes, they just don't want to see them in diff. Look at Zed's answer as the correct one.Proximate
In my testing, git config core.filemode false does not seem to affect the output from git diff when two branches (containing mode changes but nothing else) are diff'ed. This was with git 2.17.0 on Mac OS, with the local repo on an ExFAT filesystem. For some reason git diff always shows the mode changes, regardless of what core.filemode is set to.Gorilla
@Gorilla Not my experience with 2.17.1 on Ubuntu. There, Zed's hack below shows the mode changes—but only on files that do differ otherwise—and the core.fileMode=false option is identical except for not showing the filemode change. I don't know whether git cares about case in the config options, though...Ashore
I downvoted because that second command literally changes the permissions on all files. That's incredibly dangerous for someone who might blindly copy and paste that command and wonder what the heck happened.Mortimer

© 2022 - 2024 — McMap. All rights reserved.