[git] git index.lock File exists when I try to commit, but cannot delete the file

When I do 'git commit', I'm getting the following:

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

However, when I do ls project_path/.git/index.lock it's saying the file doesn't exist. Any thoughts on what I should do? I've also noticed that project_path/.git is owned by root, not sure if that has anything to do with the problem I'm encountering.

git version is 1.7.5.4

edit: It seems that the problem most likely was another process I had running, that was writing (unbeknownst to me) to the project directory. I restarted my machine and then I had no problem committing.

This question is related to git

The answer is


On Linux, Unix, Git Bash, or Cygwin, try:

rm -f .git/index.lock

On Windows Command Prompt, try:

del .git\index.lock


For Windows:

  • From a PowerShell console opened as administrator, try

    rm -Force ./.git/index.lock
    
  • If that does not work, you must kill all git.exe processes

    taskkill /F /IM git.exe
    

    SUCCESS: The process "git.exe" with PID 20448 has been terminated.
    SUCCESS: The process "git.exe" with PID 11312 has been terminated.
    SUCCESS: The process "git.exe" with PID 23868 has been terminated.
    SUCCESS: The process "git.exe" with PID 27496 has been terminated.
    SUCCESS: The process "git.exe" with PID 33480 has been terminated.
    SUCCESS: The process "git.exe" with PID 28036 has been terminated. \

    rm -Force ./.git/index.lock