git resource_error ai_generated true

致命错误:无法创建 '.git/index.lock':文件已存在。

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

ID: git/commit-not-possible-because-index-is-locked

其他格式: JSON · Markdown 中文 · English
95%修复率
85%置信度
1证据数
2023-03-15首次发现

版本兼容性

版本状态引入弃用备注
git 2.30.0 active
git 2.39.0 active
git 2.42.0 active

根因分析

之前的 git 命令崩溃或仍在运行,留下了 index.lock 文件,阻止任何新的写入操作。

English

A previous git command crashed or is still running, leaving the index.lock file, which prevents any new write operations.

generic

官方文档

https://git-scm.com/docs/git-lockfile

解决方案

  1. Remove the lock file manually: rm -f .git/index.lock
  2. Check for hanging git processes: ps aux | grep git, then kill them before removing the lock file.
  3. If using Windows, use del .git\index.lock from the repository root.

无效尝试

常见但无效的做法:

  1. 95% 失败

    Destroys all commit history and branches; overkill for a simple lock file issue.

  2. 100% 失败

    The lock file persists, so the same error occurs again.

  3. 80% 失败

    Does not remove the lock file; may lose uncommitted changes without fixing the issue.