当我试图移动我的项目树到git repo时,我仍然得到这个错误消息。

我检查了我的目录与这个项目的权限,这些设置为777。在终端的my_project目录下设置:

git init

然后如果我尝试

转到添加 。

or

Git commit -m "first upload"

我就会得到错误

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.

我也尝试创建一个新的回购,并在那里提交它,但不幸的是,仍然是相同的错误消息。

问题的原因是什么?


当前回答

你使用。git/index有问题。锁定,所以删除它使用下面的命令。

命令:

Sudo rm -rf .git/index.lock

其他回答

运行任务管理器,找到Git for windows进程并杀死它。 删除索引。锁定文件在。git文件夹下 这对我很管用!

所有的解决方案都是正确的:

Just remove .git from your corrupted repository, 

then copy this file if back from another clone (if you don't have it in another machine, just clone it).

最后,是什么改变了我:

避免使用sudo解压或复制新的。git文件夹。如果您使用超级用户权限创建。Git将无法访问。Git文件夹

当我在repo的根文件夹对应的目录的子目录中(即.git所在的目录)时,就发生了这种情况。向上移动到根目录解决了这个问题-代价是使所有文件引用更不方便,因为您必须访问path/to/folder/foo。Ext而不是foo。Ext

我也有同样的问题。我试着

rm -f ./.git/index.lock 

控制台给了我一个错误信息。然后,我尝试了

rm --force ./.git/index.lock

这很有效。

好运! 这很有效

因为我必须使用不同的答案来得到实际的解决方案(对我来说)。

这对我来说很管用:

打开您正在处理的分支 打开终端(我在Git GUI中使用终端) 输入命令:cd .git 在命令中输入p: rm -f index.lock

有些人可能不得不使用-Force而不是-f。您可以通过在终端中执行命令来检查终端的命令行,例如:git help。