Before I commit some files, how can I see the file permission changes to files? I have some files that git status says had changed and should be added to commit but git diff doesn't show anything. Thanks
Asked
Active
Viewed 2.9k times
21
-
What kind of permissions are you asking about? – Abizern Feb 23 '11 at 17:21
-
File read, write and execute permissions. I'll update the question. – Clutch Feb 23 '11 at 17:25
-
Git only tracks if a file is executable or not. – Arrowmaster Feb 23 '11 at 17:31
-
@Arrowmaster No, it tracks the full set of Unix file permissions. See [this answer](http://stackoverflow.com/questions/737673/how-to-read-the-mode-field-of-git-ls-trees-output) – Abizern Feb 23 '11 at 17:32
-
2@Abizern: While all the output shows full unix file permissions, trust me when I say that 755 and 644 are the only possible permissions it will show. If you don't believe me test it for yourself. – Arrowmaster Feb 23 '11 at 17:38
-
yep - I was trying it for myself and can see it. My bad. – Abizern Feb 23 '11 at 17:40
-
4Dude, changing the question after it's been answered is not a good thing. – Abizern Feb 23 '11 at 22:36
4 Answers
25
git log --summary
will get you what you're looking for, I think. The flag will, "Output a condensed summary of extended header information such as creations, renames and mode changes." Note the example below:
$ git log --summary
commit 8978a03a209d1cc4842a8ff14b00253cb7744895
Author: Me
Date: Wed Feb 23 12:43:30 2011 -0500
second
mode change 100644 => 100755 matrix.cc
commit e559dcbee268448d4185854c056174dcb87d3013
Author: Me
Date: Wed Feb 23 12:43:10 2011 -0500
first
create mode 100644 matrix.cc

Jeff Ferland
- 17,832
- 7
- 46
- 76
-
-
apparently the question is asking how to check permission change before committing but regardless of that, [Eugen's answer](https://stackoverflow.com/a/53465858/11190169) is better overall, since you dont need to commit to see the changes – Erfan Azary Oct 26 '22 at 18:10
18
Well, since the question has been edited to ask something different, here's a different answer:
git status -v
will list mode changes as well as diffs. You can filter this down to just mode changes by running it through grep with a context filter: git status -v | grep '^old mode' -C 1
(sample result below)
diff --git a/matrix.cc b/matrix.cc
old mode 100644
new mode 100755

Jeff Ferland
- 17,832
- 7
- 46
- 76
9
A straightforward answer to your question:
git diff --summary
will output something like this:
mode change 100644 => 100755 assets/README.md
mode change 100644 => 100755 assets/css/app.css
mode change 100644 => 100755 assets/js/app-monitor.js
mode change 100644 => 100755 assets/js/app.js`

Eugen Mihailescu
- 3,553
- 2
- 32
- 29
-
1And this `git diff --summary | grep --color 'mode change 100644 => 100755' | cut -d' ' -f7 | xargs chmod -x` would remove the execute bit so git doesn't see the files as changed. ref. https://wiki.freephile.org/wiki/Git/hacks#Ignore_File_Mode – Greg Rundlett Jan 13 '19 at 05:03
4
I used this
git status --porcelain=2 | grep '100755 100755 100644' | cut -d' ' -f9
you can change the three masks 100755 100755 100644 with ones you are looking for

MatteoOreficeIT
- 190
- 2
- 5