防止 Git 更改拉取权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12733452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Prevent Git from changing permissions on pull
提问by Simon Boudrias
When I pull change from my repositories, Git change the file permissions (actually, he change the group write
permission).
当我从我的存储库中提取更改时,Git 更改了文件权限(实际上,他更改了组write
权限)。
If I'm correct, Git should only track executable bit and this anyway can be removed using setting core.filemode
to false.
如果我是对的,Git 应该只跟踪可执行位,无论如何都可以使用设置core.filemode
为 false来删除它。
But, although the filemode is set to false (in local, global and user), when I pull, write
permission constantly change.
但是,尽管文件模式设置为 false(在本地、全局和用户中),但当我拉取时,write
权限会不断变化。
I could use a git-hooks in order to reset correct chmod, but this is some overhead and I'd prefer if there's a way to just ask git to completly ignore file mode change.
我可以使用 git-hooks 来重置正确的 chmod,但这是一些开销,我更喜欢是否有办法让 git 完全忽略文件模式更改。
Anyone know how to achieve this ?
有谁知道如何实现这一目标?
采纳答案by VonC
One config setting that mighthelp here is core.sharedRepository
, presented in the blog post "Preserving Group Write on Git Objects in a Collaborative Repository":
一个可能对这里有帮助的配置设置是core.sharedRepository
,在博客文章“在协作存储库中保留 Git 对象上的组写入”中介绍:
The solution turned out to be fairly straightforward.
In the file.git/config
, I added a line that read: "sharedRepository = group
", like so:[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true sharedRepository = group
Thereafter, new files in
.git/objects
were created with the proper permissions for group write.
(However, note that new files are group-owned by the primary group of the user account via which the push was received. If the users collaborating on the project have different primary groups, and if those users do not share membership in that set of groups, you may still run into problems.)
结果证明这个解决方案相当简单。
在文件中.git/config
,我添加了一行内容:“sharedRepository = group
”,如下所示:[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true sharedRepository = group
此后,
.git/objects
使用适当的组写入权限创建了新文件。
(但是,请注意,新文件由接收推送的用户帐户的主要组拥有。如果在项目上协作的用户具有不同的主要组,并且如果这些用户不共享该组的成员资格组,您可能仍然会遇到问题。)
Make sure of the value of your umask
:
确保您umask
的价值:
Example:
0660
will make the repo read/write-able for the owner and group, but inaccessible to others (equivalent to group unlessumask
is e.g.0022
).
示例:
0660
将使所有者和组可以读/写 repo,但其他人无法访问(相当于组,除非umask
是 eg0022
)。
回答by Deleet
The solution I use is to run the command as the userthat has the permissions you want to keep:
sudo -u user command
In this case, it could be:
在这种情况下,它可能是:
sudo -u www-data git pull
www-data
being the apache default user on Ubuntu at least.
www-data
至少是 Ubuntu 上的 apache 默认用户。
This keeps the permissions from changing. I use it when updating git repositories on my VPS, while keeping the file permissions set to the webserver user.
这可以防止权限发生变化。我在更新 VPS 上的 git 存储库时使用它,同时将文件权限设置为网络服务器用户。