【git学习】解决git提交代码时报错: Unable to create ‘XXX/.git/index.lock‘: File exists.

一、问题描述

使用git提交代码的时候,出现了Unable to create '.git/index.lock' File exists 问题,如下所示:
在这里插入图片描述

Unable to create 'D:/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 文件,操作结束后会自动删除。这样做的目的是避免同时操作同一个文件夹。

错误提示我们:

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

因此,我们删除该目录下的 .git/index.lock 文件即可
在这里插入图片描述
删除之后
在这里插入图片描述
然后重新使用git提交代码,即可成功!!!

猜你喜欢

转载自blog.csdn.net/qq446282412/article/details/123901013