Git pull with www-data permissions

时间:2013-04-25 13:13:55

标签: git

我有一个git存储库,它包含dev,test和staging分支,这些分支被拉到服务器上的vhost。我需要能够使用我的用户帐户git pull on the server但是对于由www-data用户(和组)拥有的文件。当我使用svn时,我可以使用--username --password选项sudo作为www-data和svn update,它将作为我的用户对svn进行身份验证,但保持正确的文件所有权。有没有办法用git做这个(我实际上使用ssh密钥而不是密码进行身份验证)。

1 个答案:

答案 0 :(得分:4)

您希望在您要提取的存储库中设置此选项(从git help config中提取):

  core.sharedRepository
       When group (or true), the repository is made shareable between several
       users in a group (making sure all the files and objects are
       group-writable). When all (or world or everybody), the repository will
       be readable by all users, additionally to being group-shareable. When
       umask (or false), git will use permissions reported by umask(2). When
       0xxx, where 0xxx is an octal number, files in the repository will have
       this mode value.  0xxx will override user’s umask value (whereas the
       other options will only override requested parts of the user’s umask
       value). Examples: 0660 will make the repo read/write-able for the
       owner and group, but inaccessible to others (equivalent to group
       unless umask is e.g.  0022).  0640 is a repository that is
       group-readable but not group-writable. See git-init(1). False by
       default.

要将此选项cd设置为需要具有正确组/模式的工作树或存储库(而不是您要从中提取的源存储库),然后运行git config core.sharedRepository group。它不仅为存储库中的文件设置模式,还确保它们全部归拥有存储库根目录的组所有。无论您是在存储库中本地工作还是从另一个存储库(例如,通过git://协议)推送它,该选项都会生效。

如果您已经使用错误的所有者和/或模式在存储库中创建了文件,但未设置此选项,则首先需要cd进入存储库并运行chmod -R g+rw .并且chgrp -R www-data .让它进入一致状态。