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

这适用于下一次推送,因为所有的文件都属于正确的组,但下一次有人推送一个更改时,它会在对象文件夹中创建一个新项目,该项目的默认组为组。我唯一能想到的就是改变所有开发人员签入项目的默认组,但这似乎是一种hack。什么好主意吗?谢谢。


当前回答

我通过使用ssh://基于URL而不是基于http://的URL解决了这个问题。

几天前,我使用基于http://的URL克隆了存储库。在克隆和推送之间,我不得不在我的帐户上启用2FA,随后将我的公钥添加到代码库中。

由于启用了2FA, http:// URL无法正常工作。

其他回答

修复权限

在你确定并修复了潜在的原因(见下文)后,你会想要修复权限:

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

注意,如果你想让每个人都能修改存储库,你不需要chgrp,你需要将chmod更改为sudo chmod -R a+rwX。

如果您不修复根本原因,错误将不断出现,您将不得不一遍又一遍地重新运行上述命令。

根本原因

该错误可能是由以下原因之一引起的:

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.

确保以admin身份打开命令行提示符。然后,确保项目文件不是只读的。

在windows中,您可以通过右键单击项目文件夹来检查->单击“显示更多选项”->单击“属性”->取消选择“只读”->单击“应用”

在使用git很长一段时间没有问题之后,我今天遇到了这个问题。经过一些思考,我意识到我今天早些时候把我的面具从022换成了别的东西。

其他人的所有答案都是有帮助的,例如,对有问题的目录执行chmod。但根本原因是我的新umask,每当在.git/object/下创建一个新目录时,它总是会导致一个新问题。所以,对我来说,长期的解决方案是把umask改回022。

这个问题还有一个解决方案,当你使用多个正在运行的docker容器并尝试更改和提交/推送一些东西时,这个解决方案可以重现。

在我的情况下,我不能提交任何东西,而所有的容器都在那里。但一旦我杀了他们,我就能毫无问题地投入。

我没有研究这种行为的原因,但我可以猜到,您在本地更改的代码在docker容器中重用,因为它是从根用户运行的,因此它可以更改它所使用的文件的一些权限-这可能会导致问题。

sudo chmod -R ug+w .;

基本上,.git/objects文件没有写权限。上面的代码行授予目录中所有文件和文件夹的权限。