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

- **ID:** `git/commit-not-possible-because-index-is-locked`
- **领域:** git
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.30.0 | active | — | — |
| git 2.39.0 | active | — | — |
| git 2.42.0 | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — Destroys all commit history and branches; overkill for a simple lock file issue. (95% 失败率)
- **** — The lock file persists, so the same error occurs again. (100% 失败率)
- **** — Does not remove the lock file; may lose uncommitted changes without fixing the issue. (80% 失败率)
