当我试图移动我的项目树到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目录中,没有索引。锁文件。因此,使用Git Bash shell,我运行…

cd .git
touch index.lock
rm index.lock

touch命令创建了文件,问题就解决了。

其他回答

只需转到D:/project/androidgc/。Git /此目录并删除索引。这个锁对我有用。

我认为有一个比删除文件更好的解决方案(天知道用sudo删除/创建文件时会发生什么):

git gc

尝试退出Xcode——因为它是一个git客户端,你必须退出Xcode以避免命令行上的git问题。

用这个:

rm -Force ./.git/index.lock

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