Git 错误:无法附加到 .git/logs/refs/remotes/origin/master:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2642836/
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 08:14:43  来源:igfitidea点击:

Git error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied

gitgithub

提问by Corbin Tarrant

I am having a strange issue that I can't seem to resolve. Here is what happend:

我有一个奇怪的问题,我似乎无法解决。这是发生的事情:

I had some log files in a github repository that I didn't want there. I found this script that removes files completely from git history like so:

我在 github 存储库中有一些我不想要的日志文件。我发现这个脚本可以从 git 历史记录中完全删除文件,如下所示:

    #!/bin/bash
set -o errexit

# Author: David Underhill
# Script to permanently delete files/folders from your git repository.  To use 
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2

if [ $# -eq 0 ]; then
    exit 0are still
fi

# make sure we're at the root of git repo
if [ ! -d .git ]; then
    echo "Error: must run this script from the root of a git repository"
    exit 1
fi

# remove all paths passed as arguments from the history of the repo
files=$@
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $files" HEAD

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune

I, of course, made a backup first and then tried it. It seemed to work fine. I then did a git push -f and was greeted with the following messages:

我当然是先备份了再试。它似乎工作正常。然后我做了一个 git push -f 并收到以下消息:

error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
error: Cannot update the ref 'refs/remotes/origin/master'.

Everything seems to have pushed fine though, because the files seem to be gone from the GitHub repository, if I try and push again I get the same thing:

不过,一切似乎都推得很好,因为文件似乎从 GitHub 存储库中消失了,如果我再次尝试推,我会得到同样的结果:

error: Unable to append to .git/logs/refs/remotes/origin/master: Permission denied
error: Cannot update the ref 'refs/remotes/origin/master'.
Everything up-to-date

EDIT

编辑

$ sudo chgrp {user} .git/logs/refs/remotes/origin/master
$ sudo chown {user} .git/logs/refs/remotes/origin/master
$ git push
Everything up-to-date

Thanks!

谢谢!

EDIT

编辑

Uh Oh. Problem. I've been working on this project all night and just went to commit my changes:

哦哦。问题。我整晚都在研究这个项目,然后就去提交我的更改:

error: Unable to append to .git/logs/refs/heads/master: Permission denied
fatal: cannot update HEAD ref

So I:

所以我:

sudo chown {user} .git/logs/refs/heads/master
sudo chgrp {user} .git/logs/refs/heads/master

I try the commit again and I get:

我再次尝试提交,我得到:

error: Unable to append to .git/logs/HEAD: Permission denied
fatal: cannot update HEAD ref

So I:

所以我:

sudo chown {user} .git/logs/HEAD
sudo chgrp {user} .git/logs/HEAD

And then I try the commit again:

然后我再次尝试提交:

16 files changed, 499 insertions(+), 284 deletions(-)
create mode 100644 logs/DBerrors.xsl
delete mode 100644 logs/emptyPHPerrors.php
create mode 100644 logs/trimXMLerrors.php
rewrite public/codeCore/Classes/php/DatabaseConnection.php (77%)
create mode 100644 public/codeSite/php/init.php
$ git push
Counting objects: 49, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 7.72 KiB, done.
Total 27 (delta 15), reused 0 (delta 0)
To [email protected]:IAmCorbin/MooKit.git
59da24e..68b6397  master -> master

Hooray. I jump on http://GitHub.comand check out the repository, and my latest commit is no where to be found. ::scratch head:: So I push again:

万岁。我跳转到http://GitHub.com并查看存储库,但找不到我最新的提交。::scratch head:: 所以我再次推动:

Everything up-to-date

Umm...it doesn't look like it. I've never had this issue before, could this be a problem with github? or did I mess something up with my git project?

嗯……看起来不像。我以前从未遇到过这个问题,这可能是 github 的问题吗?还是我的 git 项目搞砸了?

EDIT

编辑

Nevermind, I did a simple:

没关系,我做了一个简单的:

git push origin master

and it pushed fine.

它推得很好。

回答by Charles Duffy

This looks like you ran git as root locally, thus changing ownership on some of the files tracking the location of the originbranch.

这看起来像您在本地以 root 身份运行 git,从而更改了跟踪origin分支位置的某些文件的所有权。

Fix the file ownership, and you should be fine:

修复文件所有权,你应该没问题:

# run this from the root of the git working tree
sudo chown -R "${USER:-$(id -un)}" .

回答by Parineetha

In my case I created the files with root permission locally and tried to push the code to remote with local permissions. So I ran this command

就我而言,我在本地创建了具有 root 权限的文件,并尝试使用本地权限将代码推送到远程。所以我运行了这个命令

$find . -user root

to find out what all files have "root" as owner. And then I changed owner for all the files that are under root to local using following command

找出所有文件的所有者为“root”。然后我使用以下命令将 root 下所有文件的所有者更改为本地

$sudo chown parineethat `find . -user root`

Then I was able to push my code from local to remote.

然后我能够将我的代码从本地推送到远程。

回答by Andrew E

Let's concentrate on what it's complaining about exactly:

让我们专注于它到底抱怨的是什么:

Permission denied error: Cannot update the ref 'refs/remotes/origin/master'.

权限被拒绝错误:无法更新引用“refs/remotes/origin/master”。

Before doing recursive mod/ownership changes, traverse your way to that file and fix any permissions that are incorrect.

在进行递归修改/所有权更改之前,遍历该文件并修复任何不正确的权限。

I think I caused this issue by creating a branch while I was root and then trying to mess with that branch as my user.

我想我是通过在我是 root 时创建一个分支然后试图以我的用户身份弄乱该分支而导致这个问题的。

回答by Donald L Wilson

This will change all your .git files and directories recursively (from root to 1000)and give you a full listing of all the changes made in the terminal.

这将递归地更改您的所有 .git 文件和目录(从 root 到 1000),并为您提供在终端中所做的所有更改的完整列表。

sudo chown -Rc $UID .git/

须藤 chown -Rc $UID .git/

回答by Morgan Koh

I've tried fixing the ownership for Git, but it still doesn't work.

我已经尝试修复 Git 的所有权,但它仍然不起作用。

But, I've managed to fix it by creating the local branch with a different name and delete it.

但是,我设法通过创建具有不同名称的本地分支并将其删除来修复它。

Then, I check out the very same branch name again and it works.

然后,我再次查看完全相同的分支名称并且它有效。

TLDR;

TLDR;

I can't checkout `staging/rc'.

我无法结帐`staging/rc'。

So, I checkout using staginginstead that the remote is pointing to `staging/rc'.

所以,我结帐时使用staging遥控器指向“staging/rc”。

And, I delete it and checkout again. But, this time I use staging/rcas my local branch name.

而且,我删除它并再次结帐。但是,这次我staging/rc用作我的本地分支名称。

It works and I've no idea why.

它有效,我不知道为什么。

回答by Viru

Please first give the permissions from rootaccount like below

请首先从root如下帐户中授予权限

chmod -R 777 foldername

after that run the commit command

之后运行提交命令