Git推送错误:将对象添加到存储库数据库的权限不足 [英] Git Push Error: insufficient permission for adding an object to repository database

查看:421
本文介绍了Git推送错误:将对象添加到存储库数据库的权限不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试推送到共享的git远程时,出现以下错误:
将对象添加到存储库数据库的权限不足



然后我在这里阅读有关修复的信息:修复此工作对于下一次推送,因为所有文件都是正确的组,但下次有人推动更改时,它会在对象文件夹中创建一个新项目,该项目的默认组为组。我能想到的唯一的事情就是改变开发者的所有默认组,以便他们检查项目,但这似乎是一种黑客攻击。有任何想法吗?

解决方案

修复权限



确定并修复(请参阅下文),您需要修复权限:

  cd /path/to/repo.git 
chgrp -R组名。
chmod -R g + rwX。
找到。 -type d -exec chmod g + s'{}'+

如果您不修复底层原因,错误会继续回来,你将不得不一直重复运行上述命令。



相关原因



错误可能是由以下原因造成的:




  • 存储库未配置成为共享库(参见 git help config 中的 core.sharedRepository )。如果输出:

      git config core.sharedRepository 

    不是群组 true 1 或者一些掩码,尝试运行:

      git config core.sharedRepository group 

    然后重新运行递归 chmod chgrp (请参阅上面的修复权限)。

  • 操作系统不解释目录上的setgid位因为所有新文件和子目录应该继承组所有者。


    $ b core.sharedRepository true group ,Git依赖于GNU操作系统的特性(例如,每个Linux发行版)来确保新创建的子目录由正确的组(所有存储库用户所在的组)拥有。该功能记录在 GNU coreutils文档中:


    ... [如果]设置了目录的set-group-ID位,新创建的子文件继承与目录相同的组,创建的子目录继承父目录的set-group-ID位。 ...通过减少使用 chmod chown 的需要,[此机制可让用户]更轻松地共享文件。共享新文件。


    然而,并非所有操作系统都具有此功能(NetBSD就是一个例子)。对于这些操作系统,您应该确保所有Git用户拥有相同的默认组。或者,您可以通过运行 git config core.sharedRepository world 来使存储库具有全局可写性(但要小心 - 这不太安全)。


  • 文件系统不支持setgid位(例如,FAT)。 ext2,ext3,ext4都支持setgid位。据我所知,不支持setgid位的文件系统也不支持组所有权的概念,因此无论如何所有文件和目录都归同一个组所有(哪个组是挂载选项)。在这种情况下,请确保所有Git用户都在拥有文件系统中所有文件的组中。

  • 并非所有Git用户都在拥有存储库目录的同一组中。确保目录上的群组所有者是正确的,并且所有用户都在该群组中。


When I try to push to a shared git remote, I get the following error: insufficient permission for adding an object to repository database

Then I read about a fix here: Fix This worked for the next push, since all of the files were of the correct group, but the next time someone pushed up a change it made a new item in the objects folder that had their default group as the group. The only thing I can think of is to change all of the developer's default group for items they check in, but that seems like a hack. Any ideas? Thanks.

解决方案

Repair Permissions

After you have identified and fixed the underlying cause (see below), you'll want to repair the permissions:

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

If you do not fix the underlying cause, the error will keep coming back and you'll have to keep re-running the above commands over and over again.

Underlying Causes

The error could be caused by one of the following:

  • The repository isn't configured to be a shared repository (see core.sharedRepository in git help config). If the output of:

    git config core.sharedRepository
    

    is not group or true or 1 or some mask, try running:

    git config core.sharedRepository group
    

    and then re-run the recursive chmod and chgrp (see "Repair Permissions" above).

  • The operating system doesn't interpret a setgid bit on directories as "all new files and subdirectories should inherit the group owner".

    When core.sharedRepository is true or group, Git relies on a feature of GNU operating systems (e.g., every Linux distribution) to ensure that newly created subdirectories are owned by the correct group (the group that all of the repository's users are in). This feature is documented in the GNU coreutils documentation:

    ... [If] a directory's set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. ... [This mechanism lets] users share files more easily, by lessening the need to use chmod or chown to share new files.

    However, not all operating systems have this feature (NetBSD is one example). For those operating systems, you should make sure that all of your Git users have the same default group. Alternatively, you can make the repository world-writable by running git config core.sharedRepository world (but be careful—this is less secure).

  • The file system doesn't support the setgid bit (e.g., FAT). ext2, ext3, ext4 all support the setgid bit. As far as I know, the file systems that don't support the setgid bit also don't support the concept of group ownership so all files and directories will be owned by the same group anyway (which group is a mount option). In this case, make sure all Git users are in the group that owns all the files in the file system.
  • Not all of the Git users are in the same group that owns the repository directories. Make sure the group owner on the directories is correct and that all users are in that group.

这篇关于Git推送错误:将对象添加到存储库数据库的权限不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆