I have recenlty changed system and few files started appearing in git diff. Its due to mode change and am ok with that for now.
I am wondering why git diff displaying mode 755, when it supposed to 775. In below screen all linux command says it is 775, but git diff says it is 755.
OS is Ubuntu 22.04.
2
Answers
Git only stores one bit (as in binary digit) of "mode" information per ordinary file: "executable" (
+x
) or "not executable" (-x
). This single bit of mode information is, however, stored asmode 100755
(+x
) ormode 100644
(-x
).It’s no coincidence that
100755
corresponds to a Linux0755
file mode: in fact, the100
part is fromS_IFREG
in<sys/stat.h>
. Likewise100644
corresponds to a file whose mode is0644
orrw-r--r--
. In the distant past, Git did store more mode bits per file. But this was discovered to be a mistake, so now Git stores only the one mode bit—but uses the same encoding it used back when it stored more bits.The actual file permission bits that you’ll find on disk will depend on your
umask
setting, not on themode 100755
setting. If you haveumask 022
, Git will create executable files with mode 0755 orrwxr-xr-x
. If you change your umask to002
, Git will create such files with mode 0775 orrwxrwxr-x
. But the old and/or newmode
as shown ingit diff
output will always be either100644
or100755
, and that means-x
or+x
respectively.When storing a file (blob) in Git, there are only two possible file modes: 644 or 755. That is, Git stores only the executable bit, and if it is set, it stores the latter, and if not, it stores the former. Thus, for diffs, Git will only reflect whether the executable bit is set and will always use one of those two modes.
In the working tree, Git uses the umask to set permissions, which explains why your files are actually 775.