当我试图移动我的项目树到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.

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

问题的原因是什么?


当前回答

如果它是一个子模块,在你的存储库目录上试试这个:

rm -f ../.git/modules/submodule-name/index.lock

将submodules-name更改为子模块名称。

其他回答

如果它是一个子模块,在你的存储库目录上试试这个:

rm -f ../.git/modules/submodule-name/index.lock

将submodules-name更改为子模块名称。

Try

rm -f ./.git/index.lock

在存储库目录中。错误消息非常明确地说明了导致错误的原因,因此如果没有其他git进程正在运行(这是正常情况),请继续删除该文件。

在Windows中,我只能在任务管理器中为所有Git Windows(32位)进程结束任务后删除锁文件。

解决方案(win10)

1. 结束任务管理器中所有Git Windows(32位)进程的任务

2. 删除.git/index。锁文件

在这种情况下,无论出于什么原因,你正在从一个由云服务(dropbox, drive, onedrive等)同步的文件夹进行重基,你应该暂停或关闭同步,因为它会影响重基期间的权限。

在我的.git目录中,没有索引。锁文件。因此,使用Git Bash shell,我运行…

cd .git
touch index.lock
rm index.lock

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