【问题标题】:Git pull with www-data permissions具有 www-data 权限的 Git 拉取
【发布时间】:2013-04-25 13:13:55
【问题描述】:

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

【问题讨论】:

  • 实际上,在重新阅读您的问题时,我并不清楚。 哪些文件需要归该用户和组所有?受版本控制的“真实”文件,.git 目录中的 Git 文件,还是两者兼而有之?如果您尝试从 Git 存储库为网站提供服务,则只需要“真实”文件即可拥有该用户;如果您尝试共享存储库,或允许通过 HTTP 访问存储库,则需要 Git 的文件才能拥有该用户。

标签: git


【解决方案1】:

您想在要拉入的存储库中设置此选项(从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 . 以让它进入一个一致的状态。

【讨论】:

  • 感谢您的回答。我这样做的主要问题是我无法访问 git 存储库本身,因为它位于第三方基础架构上。我正在考虑将这一切转移到 GitHub,但我不知道这是否会让我的生活更轻松。
  • 不要忘记,在 Git 中,每个工作副本都有自己的存储库:repository 并不意味着 upstream。您只需要在您希望拥有正确组/模式的存储库上进行此设置。您不需要对您从中提取的原始存储库执行任何操作。
猜你喜欢
  • 2014-09-05
  • 2019-07-11
  • 2022-01-09
  • 2014-08-18
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
相关资源
最近更新 更多