Unable to create 'D:/project/xxx/.git/index.lock': File exists.

问题描述

使用git提交代码或者切换分支的时候,出现了Unable to create ‘D:/project/xxx/.git/index.lock’: File exists.的报错,如下所示:

Unable to create 'D:/project/xxx/.git/index.lock': File exists. 

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Git 执行操作时会自动生成 index.lock 文件,操作结束后会自动删除。这样做的目的是避免同时操作同一个文件夹。而出现上述报错的原因,就是由于某些缘故(比如操作过快,上一步进程没结束,下一步操作就开始)导致index.lock 文件没有自动删除

解决办法

实际上解决这个问题很简单,删掉.git目录下的index.lock文件即可
在这里插入图片描述
然后即可正常执行git命令,如提交、切换分支等。

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐