4

我有一个 git 存储库,其中包含开发、测试和暂存分支,这些分支被拉到服务器上的虚拟主机上。我需要能够使用我的用户帐户在服务器上进行 git pull,但对于被拉取的文件归 www-data 用户(和组)所有。当我使用 svn 时,我可以 sudo as www-data 和 svn update 使用 --username --password 选项,这将作为我的用户对 svn 进行身份验证,但保持正确的文件所有权。有没有办法用 git 来做到这一点(我实际上使用 ssh 密钥而不是密码进行身份验证)。

4

1 回答 1

6

您想在要拉入的存储库上设置此选项(从 中提取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 .使其进入一致状态。

于 2013-04-25T13:23:54.877 回答