防止 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:35:02  来源:igfitidea点击:

Prevent Git from changing permissions on pull

gitversion-control

提问by Simon Boudrias

When I pull change from my repositories, Git change the file permissions (actually, he change the group writepermission).

当我从我的存储库中提取更改时,Git 更改了文件权限(实际上,他更改了组write权限)。

If I'm correct, Git should only track executable bit and this anyway can be removed using setting core.filemodeto false.

如果我是对的,Git 应该只跟踪可执行位,无论如何都可以使用设置core.filemode为 false来删除它。

But, although the filemode is set to false (in local, global and user), when I pull, writepermission 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/objectswere 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: 0660will make the repo read/write-able for the owner and group, but inaccessible to others (equivalent to group unless umaskis e.g. 0022).

示例:0660将使所有者和组可以读/写 repo,但其他人无法访问(相当于组,除非umask是 eg 0022)。

回答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-databeing 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 存储库时使用它,同时将文件权限设置为网络服务器用户。