Linux Git:索引文件打开失败:“git status”的权限被拒绝。托管在 Bitbucket 上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15255785/
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: index file open failed: Permission denied on "git status". Hosted on Bitbucket
提问by demogar
I've been having this issue for the last couple of days when trying to make, either, a git status or git pull. The repository is hosted on Bitbucket.
过去几天我一直在尝试制作 git status 或 git pull 时遇到这个问题。该存储库托管在 Bitbucket 上。
Tried several things to make this work (there are some posts related to this on stackoverflow, but they didn't work).
尝试了几件事情来完成这项工作(stackoverflow 上有一些与此相关的帖子,但没有奏效)。
Here is the issue:
这是问题:
user@Host:/repo/$ git status fatal: index file open failed: Permission denied fatal: git status --porcelain failed
If I do a "git pull":
如果我做一个“git pull”:
user@Host:/repo/$ git pull remote: Counting objects: 77, done. remote: Compressing objects: 100% (30/30), done. remote: Total 56 (delta 37), reused 41 (delta 22) error: insufficient permission for adding an object to repository database .git/objects fatal: failed to write object fatal: unpack-objects failed
I double checked the local permissions and everything seems to be fine. I have permission to all the files.
我仔细检查了本地权限,一切似乎都很好。我对所有文件都有权限。
Note:
笔记:
If I use "sudo" everything seem to work as regular, however I don't have any SSH credentials for root on that deployment machine. It makes me think it is an issue with permissions (as the error explains), however: what it could be, if I'm the owner of all the files, including the files inside .git/
如果我使用“sudo”,一切似乎都正常工作,但是我在该部署机器上没有任何 root 的 SSH 凭据。它让我认为这是权限问题(如错误所解释的),但是:如果我是所有文件的所有者,包括 .git/ 中的文件,它可能是什么
Thanks in advance!
提前致谢!
采纳答案by Kjuly
Got the same error fatal: index file open failed: Permission denied
by run git status
, and I checked .git/index
by
fatal: index file open failed: Permission denied
运行得到同样的错误git status
,我检查.git/index
了
$ ls -al .git/index
to my surprise, it's
令我惊讶的是,它是
---------- 1 Kjuly staff 768248 Sep 2 11:07 .git/index
I've no idea why & how it changed. Anyway, after I changed it's permission back to 644
by
我不知道为什么以及如何改变。反正以后我改变了它的许可回644
用
$ chmod 644 .git/index
git status
works.
git status
作品。
回答by knittl
Make sure the .git directory and its files/subdirectories are owned and writable by your user. This sounds like the repository was either cloned under a different user account or as root user (e.g. through sudo
).
确保 .git 目录及其文件/子目录由您的用户拥有和写入。这听起来像是存储库被克隆到不同的用户帐户下或作为 root 用户(例如通过sudo
)。
It does not matter where the remote of the repository is hosted, git status only accesses the local repository.
远程仓库的托管位置无关紧要,git status 只访问本地仓库。
回答by Kmeixner
I experienced the same problem with BitBucket today. Here is the workaround that worked for me:
我今天在 BitBucket 上遇到了同样的问题。这是对我有用的解决方法:
git remote set-url origin https://[email protected]/_my_/_repo_.git
git pull
git push
git remote set-url origin [email protected]:_my_/_repo_.git