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

查看:28
本文介绍了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

然后我在这里读到了一个修复:Fix 这适用于下一次推送,因为所有这些文件属于正确的组,但是下次有人提出更改时,它在对象文件夹中创建了一个新项目,该项目将其默认组作为该组.我唯一能想到的是更改他们签入的项目的所有开发人员的默认组,但这似乎是一个黑客.有任何想法吗?谢谢.

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
sudo chgrp -R groupname .
sudo chmod -R g+rwX .
sudo find . -type d -exec chmod g+s '{}' +

请注意,如果您希望每个人都能够修改存储库,则不需要 chgrp 并且您需要将 chmod 更改为 sudo chmod -R a+rwX .

Note if you want everyone to be able to modify the repository, you don't need the chgrp and you will want to change the chmod to sudo chmod -R a+rwX .

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

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.

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

The error could be caused by one of the following:

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

  • 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

不是 grouptrue1 或某些掩码,请尝试运行:

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

 git config core.sharedRepository group

然后重新运行递归chmodchgrp(参见上面的修复权限").

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

操作系统不会将目录上的 setgid 位解释为所有新文件和子目录都应继承组所有者".

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

core.sharedRepositorytruegroup 时,Git 依赖于 GNU 操作系统(例如,每个 Linux 发行版)的一个特性来确保新创建的子目录归正确的组(所有存储库用户所在的组)所有.此功能记录在 GNU coreutils 文档:

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:

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

... [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.

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

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).

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

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.

并非所有 Git 用户都在拥有存储库目录的同一组中.确保目录中的组所有者正确并且所有用户都在该组中.

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天全站免登陆