我注意到,当我从开发服务器 (Red Hat) 上的 github 存储库中 pull 文件时,文件的所有权在 pull 完成后发生了变化。 .git 文件曾经归我所有,但后来我注意到它会以我的身份写入文件,而我需要它以不同的用户身份写入文件。所以我更改了 .git 目录的所有权。
我偶然发现 git config core.filemode
是真的。我已经把它设置为 false。将其设置为 false 后,我没有看到任何区别。我应该怎么做才能防止我的文件所有权发生变化。
这不会发生在我本地。
最佳答案
如果足以保留组,您可以在目录上设置 setgid 标志。参见 http://en.wikipedia.org/wiki/Setuid
Setting the setgid permission on a directory ("chmod g+s") causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner ID is never affected, only the group ID). Newly created subdirectories inherit the setgid bit. Thus, this enables a shared workspace for a group without the inconvenience of requiring group members to explicitly change their current group before creating new files or directories. Note that setting the setgid permission on a directory only affects the group ID of new files and subdirectories created after the setgid bit is set, and is not applied to existing entities. Setting the setgid bit on existing subdirectories must be done manually, with a command such as the following:
[root@foo]# find /path/to/directory -type d -exec chmod g+s '{}' \;
关于git - 如何防止 git 更改文件所有权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15076348/