40

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.

Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
  • 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. –  May 31 '18 at 14:14

2 Answers2

95
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.

Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
Zed
  • 3,457
  • 3
  • 20
  • 21
  • 1.7.9.5 Also appears to be too old :( – ThorSummoner Jun 02 '15 at 18:00
  • 20
    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. – PseudoNoise Oct 26 '15 at 19:47
  • 7
    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? – Stéphane Gourichon Nov 19 '15 at 15:58
  • I'm surprised this didn't get more upvotes. Does the trick for me, since core.fileMode does not affect change in write permissions. – Gerard van Helden Aug 18 '16 at 14:07
  • 1
    I think this will also hide deletions. – Frank Robert Anderson Feb 13 '17 at 22:23
  • 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? – ARF Jan 06 '18 at 11:24
  • I realised that this is a Git for Windows issue. Solution in [this SO post](https://stackoverflow.com/questions/9656552/how-to-turn-off-git-1-7-8-overhead-for-binary-files-doc-pdf-etc). – ARF Jan 06 '18 at 18:18
  • 1
    @FrankRobertAnderson I'm using it right now, and it is not hiding the deletions – Auspex Jan 10 '19 at 13:29
  • 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. – jez Aug 10 '20 at 15:39
  • This also hides empty files (obviously). – tukusejssirs Aug 04 '22 at 12:58
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
Ashish Chopra
  • 1,413
  • 9
  • 23
  • 8
    I don't want GIT to ignore my file permission changes. I want git diff to not show them... – Hommer Smith Mar 13 '14 at 19:31
  • 1
    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. – okwme Apr 10 '15 at 09:28
  • 6
    @HommerSmith, This should work for your need: `git -c core.fileMode=false diff` Courtesy: http://stackoverflow.com/a/1580644/749232 – saji89 Aug 07 '15 at 09:12
  • 3
    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. – Stéphane Gourichon Nov 19 '15 at 16:03
  • 2
    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. – Frank Robert Anderson Feb 13 '17 at 21:41
  • 1
    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. – James Jun 29 '18 at 15:59
  • 1
    @James 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... – Auspex Jan 10 '19 at 13:38
  • 1
    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. – gerrard00 May 01 '20 at 04:19