本文最后更新于 2023-05-14,文章内容可能已经过时。

今天使用git的时候,因为输错了命令然后我就强制终止了git。再过一会我拉取代码,就报错了,内容如下。

其实解决的办法很简单,直接删除 .git 文件夹内的 index.lock 文件就可以了。

友情提示:使用git工具的过程中,最好不要轻易的强制杀掉进程,不然会导致很多莫名其妙的错误。

报错内容:

fatal: Unable to create 'E:/ShimmerLS_blog/.deploy_git/.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.
FATAL {
  err: Error: Spawn failed
      at ChildProcess.<anonymous> (E:\ShimmerLS_blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
      at ChildProcess.emit (node:events:379:20)
      at ChildProcess.cp.emit (E:\ShimmerLS_blog\node_modules\cross-spawn\lib\enoent.js:34:29)
      at Process.ChildProcess._handle.onexit (node:internal/child_process:285:12) {
    code: 128
  }
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html