当我试图移动我的项目树到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的GUI应用程序收到相同的问题,出错了,git使一些工作无限。kill进程将冻结使用git的应用程序,只需重新启动它,一切都会好起来。

其他回答

重启机器对我有用。到目前为止,提供的解决方案没有一个对我有效。

环境 视窗 10 + Git Bash

编辑:我看到同样的解决方案是在这里:git索引。提交时文件存在,但无法删除

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

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

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

如果你尝试之后:

Rm -f ./.git/index.lock

你会得到:

Rm:不能断开索引。lock':拒绝允许

尝试关闭所有可能使用Git的软件。 我打开了源代码树和Visual Studio,关闭后命令都工作了。

我尝试了很多方法,但这个方法对我来说很有效(我使用了PyCharm的终端):

$ cd .git/

$ rm -f index.lock

然后我再次尝试创建一个空的git回购:

$ git init

$ git add .

$ git commit -m "commit msg"

我也有这个问题,而且我发现这真的是一个许可问题。所以我这样做:

sudo chown -R : .git #change group
sudo chmod -R 775 .git #change permission

那么一切都是伟大的,gaa是成功。

然后我用gp,得到另一个几乎相同的错误

sudo chown -R "${USER:-$(id -un)}" . #use this can fix the problem