git - 如何防止 git 更改文件所有权

标签 git file ownership

我注意到,当我从开发服务器 (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/

相关文章:

c# - Google Drive SDK 为用户创建文件

Git 设置允许强制更新某些分支

c - C 中逐字符、逐行读取文件

file - node.js 文件内存泄漏?

string - 是否有 String::chars 的自有版本?

rust - 在 Rust 中使用引用和使用拥有的值有区别吗?

git - 我从 bitbucket 的部署失败并显示错误。如何找到 Azure D : drive to delete the file?

git - 为什么我不能推送我的新分支?

ruby-on-rails - 无法将主分支推送到 Git 中的 Heroku

perl - 使用 Perl 从 2 个文件逐行打开和读取