[英]git diff displaying wrong file mode - instead of 775 displaying 755
I have recenlty changed system and few files started appearing in git diff.我最近更改了系统,并且很少有文件开始出现在 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.我想知道为什么 git diff 显示模式 755,而它应该是 775。在下面的屏幕中,所有 linux 命令都说它是 775,但 git diff 说它是 755。
OS is Ubuntu 22.04.操作系统是 Ubuntu 22.04。
Git only stores one bit (as in binary digit) of "mode" information per ordinary file: "executable" ( +x
) or "not executable" ( -x
). Git 仅存储每个普通文件的“模式”信息的一位(如二进制数字):“可执行”( +x
)或“不可执行”( -x
)。 This single bit of mode information is, however, stored as mode 100755
( +x
) or mode 100644
( -x
).然而,这一单比特模式信息存储为mode 100755
( +x
) 或mode 100644
( -x
)。
It's no coincidence that 100755
corresponds to a Linux 0755
file mode: in fact, the 100
part is from S_IFREG
in <sys/stat.h>
. 100755
对应于 Linux 0755
文件模式并非巧合:实际上, 100
部分来自<sys/stat.h>
S_IFREG
Likewise 100644
corresponds to a file whose mode is 0644
or rw-r--r--
.同样100644
对应于模式为0644
或rw-r--r--
的文件。 In the distant past, Git did store more mode bits per file .在遥远的过去,Git 确实为每个文件存储了更多的模式位。 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.但后来发现这是一个错误,所以现在 Git 只存储一个模式位,但使用它在存储更多位时使用的相同编码。
The actual file permission bits that you'll find on disk will depend on your umask
setting, not on the mode 100755
setting.您将在磁盘上找到的实际文件权限位取决于您的umask
设置,而不是mode 100755
设置。 If you have umask 022
, Git will create executable files with mode 0755 or rwxr-xr-x
.如果你有umask 022
,Git 将创建模式为 0755 或rwxr-xr-x
可执行文件。 If you change your umask to 002
, Git will create such files with mode 0775 or rwxrwxr-x
.如果您将 umask 更改为002
,Git 将使用 0775 或rwxrwxr-x
模式创建此类文件。 But the old and/or new mode
as shown in git diff
output will always be either 100644
or 100755
, and that means -x
or +x
respectively.但是git diff
输出中显示的旧模式和/或新mode
将始终为100644
或100755
,这分别表示-x
或+x
。
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.在 Git 中存储文件(blob)时,只有两种可能的文件模式:644 或 755。也就是说,Git 只存储可执行位,如果设置了,则存储后者,如果没有,则存储以前的。 Thus, for diffs, Git will only reflect whether the executable bit is set and will always use one of those two modes.因此,对于差异,Git 只会反映是否设置了可执行位,并将始终使用这两种模式之一。
In the working tree, Git uses the umask to set permissions, which explains why your files are actually 775.在工作树中,Git 使用 umask 设置权限,这就解释了为什么你的文件实际上是 775。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.