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
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.
官方文档
https://git-scm.com/docs/git-lockfile解决方案
-
Remove the lock file manually: rm -f .git/index.lock
-
Check for hanging git processes: ps aux | grep git, then kill them before removing the lock file.
-
If using Windows, use del .git\index.lock from the repository root.
无效尝试
常见但无效的做法:
-
95% 失败
Destroys all commit history and branches; overkill for a simple lock file issue.
-
100% 失败
The lock file persists, so the same error occurs again.
-
80% 失败
Does not remove the lock file; may lose uncommitted changes without fixing the issue.