Git - 致命:无法创建“/path/my_project/.git/index.lock”:文件存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7860751/
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 - fatal: Unable to create '/path/my_project/.git/index.lock': File exists
提问by user984621
I am still getting this error message, when I try to move my project tree on to git repo.
当我尝试将我的项目树移动到 git repo 时,我仍然收到此错误消息。
I checked the permissions of my directory with this project and these are set on 777. In terminal in the directory with my_project
I set:
我用这个项目检查了我的目录的权限,这些权限是在 777 上设置的。在my_project
我设置的目录中的终端中:
git init
git初始化
and then if I try
然后如果我尝试
git add .
git 添加。
or
或者
git commit -m "first upload"
git commit -m "第一次上传"
so I'll get the error
所以我会得到错误
fatal: Unable to create '/path/my_proj/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
I tried also create a new repo and there to commit it, but unfortunately still the same error message.
我还尝试创建一个新的 repo 并在那里提交它,但不幸的是仍然出现相同的错误消息。
What is the cause of problem?
问题的原因是什么?
回答by Raphael R.
Try
尝试
rm -f ./.git/index.lock
In your repository directory. The error message is rather explicit as to what causes it typically, so if you have no other git processes running (which is the normal case), go ahead and delete that file.
在您的存储库目录中。错误消息对于通常导致它的原因非常明确,因此如果您没有其他 git 进程正在运行(这是正常情况),请继续并删除该文件。
回答by ssaltman
In Windows, do this in the command prompt from the repo directory:
在 Windows 中,在 repo 目录的命令提示符下执行此操作:
cd .git
del index.lock
UPDATE: I have found that I don't need to do this procedure if I wait a moment after I close out the files I'm working on before I try to switch branches. I think sometimes this issue occurs due to git catching up with a slow file system. Other, more git-knowledgeable developers can chime in if they think this is correct.
更新:我发现如果我在关闭正在处理的文件后等待片刻,然后再尝试切换分支,则不需要执行此过程。我认为有时这个问题是由于 git 赶上了一个缓慢的文件系统。如果他们认为这是正确的,其他更了解 git 的开发人员可以加入。
回答by Jeff Grimes
Try quitting Xcode - since it's a git client, you have to quit Xcode to avoid problems with git on the command line.
尝试退出 Xcode - 因为它是一个 git 客户端,你必须退出 Xcode 以避免在命令行中出现 git 问题。
回答by Olivia Steger
I was having the same problem. I tried
我遇到了同样的问题。我试过
rm -f ./.git/index.lock
and the console gave me an error message. Then, I tried
控制台给了我一条错误消息。然后,我试过了
rm --force ./.git/index.lock
and that worked.
这奏效了。
Good Luck! This works super
祝你好运!这个超级好用
回答by John Livermore
In my .git directory, there was no index.lock file. So, using the Git Bash shell, I ran...
在我的 .git 目录中,没有 index.lock 文件。所以,使用 Git Bash shell,我跑了......
cd .git
touch index.lock
rm index.lock
The touch command created the file, and the problem went away.
touch 命令创建了文件,问题就消失了。
回答by hktang
Did you accidentally create the repository using the
root
user?
您是否不小心使用
root
用户创建了存储库?
It just happens that I created the git repository as the root
user.
碰巧我以root
用户身份创建了 git 存储库。
I deleted the git repository and created it again without sudo
and it works.
我删除了 git 存储库并在没有的情况下再次创建它sudo
并且它可以工作。
回答by defend orca
i have this problem too, and i find it really a permission problem. so i do this:
我也有这个问题,我发现它确实是一个权限问题。所以我这样做:
sudo chown -R : .git #change group
sudo chmod -R 775 .git #change permission
then ererything is great, and gaa is success.
那么一切都很棒,而 gaa 就是成功。
and then i use gp, i get another error almost the same error
然后我使用 gp,我得到另一个错误几乎相同的错误
sudo chown -R "${USER:-$(id -un)}" . #use this can fix the problem
回答by Rick Wong
In Mac OS X do this in the command prompt from the repo directory:
在 Mac OS X 中,在 repo 目录的命令提示符下执行此操作:
cd .git
rm index.lock
回答by ChrisDeDavidMindflowAU
In Windows, I only managed to be able to delete the lock file after Ending Task for all Git Windows (32bit) processes in the Task Manager.
在 Windows 中,我只能在任务管理器中为所有 Git Windows(32 位)进程结束任务后才能删除锁定文件。
Solution(Win 10)
解决方案(Win 10)
1. End Taskfor all Git Windows (32bit) processes in the Task Manager
1.在任务管理器中结束所有 Git Windows(32 位)进程的任务
2. Deletethe .git/index.lock file
2.删除.git/index.lock文件
回答by neoswf
If you are using one of #intelliJ
IDEs and receiving this msg (i'm using #webtorm
), please notice that this problem can occur because of hiding one of project folders (inside settings), and this can prevent GIT
from merging.
如果您正在使用#intelliJ
IDE 之一并收到此消息(我正在使用#webtorm
),请注意,由于隐藏了项目文件夹之一(在设置中),可能会出现此问题,这会阻止GIT
合并。