从 git 中提取时出错 - 将对象添加到存储库数据库 .git/objects 的权限不足

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18779442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:56:41  来源:igfitidea点击:

Error while pull from git - insufficient permission for adding an object to repository database .git/objects

git

提问by unnati patil

I have git error: "insufficient permission for adding an object to repository database .git/objects" every time I make "git pull origin develop".

每次我进行“git pull origin development”时,我都会遇到 git 错误:“没有足够的权限将对象添加到存储库数据库 .git/objects”。

    remote: Counting objects: 70, done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 42 (delta 35), reused 42 (delta 35)
    error: insufficient permission for adding an object to repository database     .git/objects

    fatal: failed to write object
    fatal: unpack-objects failed

回答by dwurf

Assuming @ChrisHayes is right about an accidental sudo, this should fix it. From inside your repository:

假设@ChrisHayes 关于意外的 sudo 是正确的,这应该可以解决它。从您的存储库内部:

sudo chown -R $USER:$USER "$(git rev-parse --show-toplevel)/.git"

Update: for those of you getting the illegal group nameerror, try this instead:

更新:对于那些收到illegal group name错误的人,请尝试以下操作:

sudo chown -R $(id -u):$(id -g) "$(git rev-parse --show-toplevel)/.git"

回答by Priyank Patel

Go to project's root directory and run below commands to fix this issue,

转到项目的根目录并运行以下命令来解决此问题,

cd .git/objects
sudo chown -R yourname:yourgroup *

回答by vaindil

Mine was a stupid mistake... the right username and group were set, but www-data was the account accessing it. The directory was owned by vaindil:www-data, but permissions were 755 so www-data couldn't write to it. Fixed it with:

我的是一个愚蠢的错误......设置了正确的用户名和组,但 www-data 是访问它的帐户。该目录归 vaindil:www-data 所有,但权限为 755,因此 www-data 无法写入。修复它:

$ sudo chmod -R 775 /path/to/repo

回答by Nabin

NOT A GOOD PRACTICE (Just an alternative)

不是一个好习惯(只是一个替代方案)

I am using Ubuntu and faced the same problem. To solve it, I simply switched user to root and I see no further error.

我正在使用 Ubuntu 并面临同样的问题。为了解决这个问题,我只是将用户切换到 root,我看不到进一步的错误。

$su
password

Then,

然后,

$git pull origin master

Recommended way: CHANGE THE PERMISSION OF THE DIRECTORY

推荐方式:更改目录的权限

回答by Gaurav Arora

remove .git from the url, if you are trying to clone a public repository from github.

如果您尝试从 github 克隆公共存储库,请从 url 中删除 .git。

example:

例子:

From: https://github.com/example/repository.gitTo: https://github.com/example/repository

来自:https: //github.com/example/repository.git至:https: //github.com/example/repository