当我做'git commit'时,我得到以下内容:

无法创建“project_path/.git/index”。lock `:文件已存在。

然而,当我执行ls project_path/.git/index。锁定,表示文件不存在。你觉得我该怎么做?我还注意到project_path/。git由root拥有,不确定这是否与我遇到的问题有关。

Git版本为1.7.5.4

编辑:看起来问题很可能是我正在运行的另一个进程,那就是向项目目录写入(我不知道)。我重新启动了我的电脑,然后我就没有问题了。


当前回答

对我来说,罪魁祸首是windows安全,它阻止了git.exe运行,你可以检查屏幕右下角的通知选项卡。

消息将如下所示

Virus and threat protection 
unauthorized changes blocked
controlled folder access blocked git.exe from running

其他回答

我在windows 10中也有这个问题。

当我尝试del ./.git/index。锁,它告诉我不能删除索引。lock':设备或资源繁忙

我终于明白了原因:

计算机有两个进程使用git:

吉特巴什 CMDER

所以我使用cder .exe来git提交它会发生错误。

所以解决方案是使用git bash或终止git bash,然后使用cder .exe

这可能是因为当你试图拉代码并突然停止进程。

简单的方法:

Rm -f ./.git/index.lock 在master/main分支的git状态之后 还能看到很多红色的文件。运行git reset——hard origin/master删除所有本地更改,使其与origin/master类似。

对我来说,罪魁祸首是windows安全,它阻止了git.exe运行,你可以检查屏幕右下角的通知选项卡。

消息将如下所示

Virus and threat protection 
unauthorized changes blocked
controlled folder access blocked git.exe from running

我的解决方案是删除.index文件,并允许Git重新构建另一个。

Windows:

从以管理员身份打开的powershell控制台尝试

> rm -Force ./.git/index.lock

如果这不起作用,您必须杀死所有git.exe进程

> taskkill /F /IM git.exe PID为20448的进程“git.exe”已被终止。 PID为11312的进程“git.exe”已被终止。 PID为23868的进程“git.exe”已被终止。 PID为27496的进程“git.exe”已被终止。 PID为33480的进程“git.exe”已被终止。 PID为28036的进程“git.exe”已被终止。 > rm -Force ./.git/index.lock