Git常见问题:fatal: Unable to create index.lock File exists 错误的解决办法

1,649 阅读1分钟

这是我参与11月更文挑战的第12天,活动详情查看:2021最后一次更文挑战

Git(读音为/gɪt/)是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。 也是Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件。

Torvalds 开始着手开发 Git 是为了作为一种过渡方案来替代 BitKeeper

Git常见问题:fatal: Unable to create index.lock File exists 错误的解决办法:在stackoverflow上找到了解决方案.

报错内容:

$ git commit -m 'Test'
fatal: Unable to create 'D:/MyProject/.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.

或者

fatal: Unable to create '/.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 文件夹。打开该文件夹。找到文件夹里面的index.lock 文件,将其删除,即可解决问题(如果提示不能删除文件,就重启系统)

或者

在当前项目下打开git bash,运行如下命令:

尝试

rm -f ./.Git/index.lock

在您的存储库目录中。

表现形式:

提交后更改数为0,修改了文件后点击保存,更改数就会变成无。形成一种脱机现象,文件修改无效,也无法上传。(感觉就像灵异事件一样的离谱)

在这里插入图片描述

产生原因:

应该是由于git操作的时候修改了一些文件导致的操作冲突被锁住了

参考链接