如何让git免受文件所有权的影响 [英] How to keep git from changing file ownership

查看:109
本文介绍了如何让git免受文件所有权的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直注意到,当我从一个开发服务器(Red Hat)上的github repo中取出文件时,拉取完成后文件的所有权会发生变化。 .git文件曾经由我拥有,但后来我注意到它会写文件作为我,我需要它作为不同的用户写文件。所以我改变了.git目录的所有权。



我偶然发现了git config core.filemode 这是真的。我既然认为它是假的。将此设置为false后我没有看到任何区别。我应该怎么做才能保证我的文件所有权不会发生变化。



这不会在本地发生。

如果 只需保留组即可,您可以在目录上设置setgid标志。请参阅 http://en.wikipedia.org/wiki/Setuid


在目录(chmod g + s)上设置setgid权限会导致在其中创建的新文件和子目录继承其组标识,而不是创建的用户的主组标识该文件(所有者ID从不受影响,只有组ID)。新创建的子目录继承setgid位。因此,这为组创建了一个共享工作区,而无需在创建新文件或目录之前要求组成员显式更改其当前组的不便之处。请注意,设置目录上的setgid权限仅影响setgid位设置后创建的新文件和子目录的组ID,并且不会应用于现有实体。设置现有子目录上的setgid位必须手动完成,并使用如下命令:

[root @ foo]#find / path / to / directory -type d -exec chmod g + s'{}'\;



I have been noticing that when I pull from my github repo on a development server(Red Hat) the ownership of the files change after the pull is completed. The .git file used to be owned by me but then I noticed that it would write files as me and I need it to write files as a different user. So i changed the ownership of the .git directory.

I stumbled on to git config core.filemode which was true. I since have set to it false. I have not seen a difference after setting this to false. What should I do to keep my files ownership from changing.

This doesn't happen to me locally.

解决方案

If it suffices to preserve the group, you can set the setgid flag on the directories. See 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免受文件所有权的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆