2010-04-15 44 views
47

我有一个奇怪的问题,我似乎无法解决。这里是发生了什么:Git错误:无法附加到.git/logs/refs/remotes/origin/master:权限被拒绝

我有一些日志文件,我不想在那里的github存储库。我发现这个脚本,从提交历史将完全删除的文件,像这样:

#!/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 
[email protected] 
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 

我,当然,做了备份,然后再尝试了。它似乎工作正常。然后我做了一个混帐推-f与以下消息迎了上去:

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

一切似乎虽然已导致罚款,因为这些文件似乎是从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 

编辑

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

谢谢!

编辑

呃哦。问题。我一直在做这个项目了一夜,刚走到提交我的变化:

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

所以我:

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

我尝试提交一次我得到:

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

所以我:

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

然后我再次尝试:

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。我跳到http://GitHub.com并查看存储库,并且我最近的提交没有找到。 ::刮头::于是我再次推:

Everything up-to-date 

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

编辑

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

git push origin master 

,并推罚款。

回答

121

这看起来像你在本地运行git,从而改变了一些跟踪origin分支位置的文件的所有权。

修复文件的所有权,你应该罚款:

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

该命令为我工作。我从克隆的根部运行它。谢谢@CharlesDuffy! – ariestav 2013-07-15 14:45:48

+2

@ Mr.Stranger,只有当你有一个理智的IFS值和用户名时(用户名才会有空格,例如在cygwin上)。更安全地引用:'sudo chown -R“$ USER”.',而不是假设理智。 :) – 2016-01-27 15:09:19

+0

@ Mr.Stranger,...另外,用户不能通过http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_05_03保证,因此使用起来可能更安全'“$(id -un)”'。 – 2016-01-27 15:13:10

-7

请先给从root帐户的权限如下图所示

chmod -R 777 foldername 

后执行commit命令

+5

这是非常危险的 - 它给了系统上的任何账号,包括一个只有“nobody”权限的被破坏的守护进程,对你的文件有写权限。系统守护进程对安全敏感的组件使用“nobody”(或其他未授权的帐户)*,因为*即使没有任何帐户被破坏,它也不应该做任何冒险的事情。通过让所有用户(甚至没有人)可以对您的文件进行写入访问,您正在使基本安全措施变得毫无用处。 – 2015-08-10 14:59:49

+1

如果出于某种原因,您希望您的文件由root拥有并可由特定的非root用户写入,那么安全的方式(在每个用户拥有自己的组的系统上,就像标准做法一样)是' chown -R root:user directory',然后是'chmod -R 775 directory'(或者'770',如果其他帐户不需要读取权限)。 – 2015-08-10 15:03:30

+1

@JasonGlisson,只有通过创建巨大的安全漏洞才能“起作用”的东西,可能会更好的保持破碎。 – 2016-03-01 05:00:20

1

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

$find . -user root 

找出所有文件有“所有者”作为所有者。然后,我改变了所有者一切都在根下使用本地以下命令

$sudo chown parineethat `find . -user root` 

然后,我能够从当地把我的代码到远程文件。

+0

'sudo chown parineethat'find。 -user root''''不可靠 - 不适用于带空格的文件名。相反,'sudo找到。 -user root -exec chown parineethat {} +'。有关相关讨论,请参见[BashPitfalls#1](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29)。 – 2017-09-25 11:21:01

0

让我们精力集中在它的抱怨究竟:

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

做递归MOD /股权变动之前,遍历自己的方式到该文件并解决任何不正确的权限。

我想我通过创建一个分支,而我是根,然后试图作为我的用户混乱与该分支导致此问题。