Git报错:fatal: Unable to create ‘.../.git/index.lock‘

1. 背景

  今天提交一份很早之前写的代码的时候,遇到git报错,报错如下:

   fatal: Unable to create '/xxx/xx/.git/index.lock': File exists.

   If no other git process is currently running, this probably means a git process crashed in this	&nbsp repository earlier. Make sure no other git process is running and remove the file manually to continue.
(译文:如果当前没有其他的git进程在运行,这可能意味着之前这个存储库中有一个git进程崩溃了。确保没有其他git进程正在运行,然后手动删除该文件以继续。)

2. 原因:

  git在执行耗时操作的时候为了避免对同一个目录进行多个操作的冲突 ,会自动生成一个index.lock文件。作为锁文件。当操作结束,git会自动删除该文件。
当git在运行过程中,用户强制关闭了git,导致git无法自动删除index.lock。导致之后git执行操作的时候,都会查询到有index.lock文件的存在,而认为有其他git进程在操作该工程,于是当前git无法进行操作。

2. 解决方法:

  进入工程根目录下的.git文件夹中手动删除index.lock文件,便可以正常运行git。如该文件夹下没有index.lock,打开显示隐藏文件查看。

猜你喜欢

转载自blog.csdn.net/qq_41546984/article/details/127573005