删除 .git/index.lock': 权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14127255/
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
remove .git/index.lock': Permission denied
提问by user1760561
I'm completely stuck as to why my git has completely locked me out. I have a laptop that I use at work and when I'm home. For both accounts I use git extensively and both are located in different paths. Today I came into work and I can't do anything, all I see is:
我完全不明白为什么我的 git 完全把我锁在外面。我有一台笔记本电脑,可以在工作和在家时使用。对于这两个帐户,我广泛使用 git,并且都位于不同的路径中。今天上班了,什么也做不了,只能看到:
/Applications/MAMP/htdocs/my_site/.git/index.lock': Permission denied
For all I care the branch I'm on can be deleted. I've tried removing the branch, checking out any other branch, removing the index.lock file (as suggested by other users on sites). I only have the terminal window open, no other possible programs using git (as far as I know and nothing noticeable in the activity window). I have rebooted the computer straight into my work account and still no luck. How can I remove this lock?
对于所有我关心的分支,我可以删除。我试过删除分支,检查任何其他分支,删除 index.lock 文件(如网站上的其他用户所建议的那样)。我只打开了终端窗口,没有其他可能使用 git 的程序(据我所知,活动窗口中没有任何明显的东西)。我已经将计算机直接重新启动到我的工作帐户中,但仍然没有运气。我怎样才能解除这个锁?
采纳答案by Jure C.
Check which user owns the git lock:
检查哪个用户拥有 git 锁:
ls -la /Applications/MAMP/htdocs/my_site/.git/index.lock
Then you can use sudo
to remove it.
然后你可以使用sudo
它来删除它。
回答by Mahshid Zeinaly
I had the exact same problem wanting to commit my changes to git, and solved it this way:
我想将更改提交到 git 时遇到了完全相同的问题,并以这种方式解决了这个问题:
I needed to change the group of my
.git
folder and its contents:sudo chown -R <owner>:<group> .git
needed to change the permission of this folder:
sudo chmod -R 775 .git
我需要更改
.git
文件夹的组及其内容:sudo chown -R <owner>:<group> .git
需要更改此文件夹的权限:
sudo chmod -R 775 .git
回答by Matthias M
After updating xcode you are maybe asked for agreeing to the new license.
更新 xcode 后,您可能会被要求同意新的许可证。
git init
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
git初始化
同意 Xcode/iOS 许可证需要管理员权限,请通过 sudo 以 root 身份重新运行。
When you do this
当你这样做时
sudo git init
须藤 git init
you'll get a root user .git dir
你会得到一个 root 用户 .git dir
drwxr-xr-x 10 root XXXX 340 25 Sep 12:40 .git
drwxr-xr-x 10 根 XXXX 340 9 月 25 日 12:40 .git
If you call other git commands which create files, these files are also created for the root user.
如果调用其他创建文件的 git 命令,也会为 root 用户创建这些文件。
Change the permissions or remove .git if you don't need it yet.
如果您还不需要它,请更改权限或删除 .git。
=> Don't ever call git with sudo!!! If your are asked to just call git on an empty directory
=> 永远不要用 sudo 调用 git !!!如果您被要求只在空目录上调用 git
mkdir foo
cd foo
sudo git init
目录 foo
cd foo
须藤 git init
回答by Jason Bruce
I had this issue as I running the following command
sudo git fetch && git checkout<branch>
我在运行以下命令时遇到了这个问题
sudo git fetch && git checkout<branch>
Note the second sudo was missing. Running the following solved the issue:
sudo git fetch && sudo git checkout<branch>
注意第二个 sudo 丢失了。运行以下解决了这个问题:
sudo git fetch && sudo git checkout<branch>
You shouldn't have to change the owner ship of the .git directory when running sudo.
运行 sudo 时,您不必更改 .git 目录的所有者。
回答by Diego Pino
I was experiencing the same issue when trying to update the submodules of my repo:
我在尝试更新我的 repo 的子模块时遇到了同样的问题:
$ git submodule update
fatal: Unable to create '.../.git/modules/deps/luajit/index.lock':
Permission denied
Unable to checkout '04dc64b558025e76a820f89a8e41840bf8269f32' in
submodule path 'deps/luajit'
It seems the problem was the submodules belonged to a different user, so I set back the ownership to me:
问题似乎是子模块属于不同的用户,所以我将所有权归还给了我:
cd .git/modules/
chown -R user.group *
回答by daidai21
My computer system is Windows. When I open WSL remote vscode and local vscode in this path, system show this error. I closed remote vscode WSL and it solved this problem.
我的电脑系统是Windows。当我在此路径中打开 WSL 远程 vscode 和本地 vscode 时,系统显示此错误。我关闭了远程 vscode WSL,它解决了这个问题。
回答by augusto
Checking permission is surely the way. I faced this error when logged in with the wrong account. So, answer from my personal experience is:
检查权限肯定是方法。我用错误的帐户登录时遇到了这个错误。所以,根据我的个人经验,答案是:
"Be sure you logged in with the correct account".
“确保您使用正确的帐户登录”。