git resource_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
95%Fix Rate
85%Confidence
1Evidence
2023-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.30.0 active
git 2.39.0 active
git 2.42.0 active

Root Cause

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

generic

中文

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

Official Documentation

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

Workarounds

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

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 100% fail

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

  3. 80% fail

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