Git pull with www-data permissions



我有一个git存储库,其中有开发,测试和暂存分支,这些分支被拉到服务器上的vhost上。我需要能够使用我的用户帐户的服务器上的git拉,但被拉的文件是由www-data用户(和组)拥有。当我使用svn时,我可以使用sudo作为www-data和svn更新,使用——username——password选项,这将对svn作为我的用户进行身份验证,但保持正确的文件所有权。有什么方法可以用git做到这一点吗(我实际上使用ssh密钥而不是密码进行身份验证)

您希望在您要拉入的存储库(从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 .以使其进入一致状态。

最新更新