Git 推送错误:无法取消旧链接(权限被拒绝)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11774397/
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
Git push error: Unable to unlink old (Permission denied)
提问by rfc1484
In the remote server I have a post-receive hook set up in order to make a git checkout of my repository:
在远程服务器中,我设置了一个 post-receive 挂钩,以便对我的存储库进行 git checkout:
#!/bin/sh
GIT_WORK_TREE=/var/www/<website> git checkout -f
But when I make a push from my local machine to the git repository in the server, I get the following error messages:
但是当我从本地机器推送到服务器中的 git 存储库时,我收到以下错误消息:
remote: error: unable to unlink old '<file>' (Permission denied)
This appears many times over, one error message for almost every file.
这多次出现,几乎每个文件都有一条错误消息。
However I have a README.txt file that I'm able to change using git, here are its permissions:
但是我有一个 README.txt 文件,我可以使用 git 更改它,这是它的权限:
-rw-r--r-- 1 <serverusername> <serverusername> 2939 Aug 2 10:58 README.txt
But other files with exactly the same owner and same permissions, give me that error.
但是其他具有完全相同所有者和相同权限的文件,给了我那个错误。
In another local repository for another website, I have the files with my local machine username as owner, and when I push to the remote server it respects the remote server owner of the files and works like a charm.
在另一个网站的另一个本地存储库中,我将文件以我的本地机器用户名作为所有者,当我推送到远程服务器时,它尊重文件的远程服务器所有者,并且像魅力一样工作。
Obviously it seems a permissions related error, but I can't find a way to fix it, any suggestions?
显然,这似乎是与权限相关的错误,但我找不到修复它的方法,有什么建议吗?
回答by Jan Marek
When you have to unlink file, you have to have permission 'w' for directory, in which file is, not for the file...
当您必须取消链接文件时,您必须对目录具有“w”权限,该文件所在的目录,而不是该文件...
回答by Rajendra kumar Vankadari
sudo chmod -R ug+w .;
This command would fix the issue. It gives write permissions to the folder.
这个命令可以解决这个问题。它授予对该文件夹的写权限。
回答by Rama Krishna Gollapudi
If you are using any IDE most likely the problem is that file was used by some process. Like your tomcat might be using the file. Try to identify that particular process and close it. That should solve your problem.
如果您正在使用任何 IDE,那么问题很可能是某个进程使用了该文件。就像您的 tomcat 可能正在使用该文件一样。尝试识别该特定进程并关闭它。那应该可以解决您的问题。
回答by wcyn
I had the same issue and none of the solutions above worked for me. I deleted the offending folder. Then:
我遇到了同样的问题,上面的解决方案都不适合我。我删除了有问题的文件夹。然后:
git reset --hard
Deleted any lingering files to clean up the git status, then did:
删除任何遗留文件以清理 git 状态,然后执行以下操作:
git pull
It finally worked.
它终于奏效了。
NOTE: If the folder was, for instance, a public folder with build files, remember to rebuild the files
注意:例如,如果文件夹是包含构建文件的公共文件夹,请记住重建文件
回答by Soumitra Sarkar
I think the problem may be with the ownership to the folder so set it to the current user ownership
我认为问题可能出在文件夹的所有权上,因此将其设置为当前用户所有权
sudo chown -R your_login_name /path/to/folder
您可以在 [此处][1] 中找到解决方案
回答by cellepo
FWIW - I had a similar problem and I'm not sure if this alleviated it (beyond the permission mod): Closing Eclipse that was using the branch with this problem.
FWIW - 我有一个类似的问题,我不确定这是否缓解了它(超出了许可模式):关闭正在使用该问题的分支的 Eclipse。
回答by kylesimmonds
This is an old question, but this may help Mac users.
这是一个老问题,但这可能对 Mac 用户有所帮助。
If you are copying files from Time Machine manually, instead of restoring them through Time Machine, it'll add ACLsto everything, which can mess up your permissions.
如果您手动从 Time Machine 复制文件,而不是通过 Time Machine 恢复它们,它将向所有内容添加ACL,这可能会扰乱您的权限。
For example, the section in this articlethat says "How to Fix Mac OS X File Permissions" shows that "everyone" has custom permissions, which messes it all up:
例如,这篇文章中“如何修复 Mac OS X 文件权限”的部分显示“每个人”都有自定义权限,这把它搞砸了:
You need to remove the ACLs from those directories/files. This Super User answergoes into it, but here's the command:
您需要从这些目录/文件中删除 ACL。这个超级用户答案进入了它,但这是命令:
sudo chmod -RN .
sudo chmod -RN .
Then you can make sure your directories and files have the proper permissions. I use 750
for directories and 644
for files.
然后您可以确保您的目录和文件具有适当的权限。我750
用于目录和644
文件。
回答by Phil Carter
I get this error, and other strange git errors, when I have a server running (in Intellij). Stopping the server and re-trying the git command frequently fixes it for me.
当我运行服务器时(在 Intellij 中),我收到此错误和其他奇怪的 git 错误。停止服务器并重新尝试 git 命令经常为我修复它。
回答by kreker
git reset --hard
Worked for me
对我来说有效
回答by BARJ
sudo chown -R $USER:$USER .
Did the job for me.
为我做了这项工作。