Advertisement
Advertisement


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


Question

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.

2012/02/15
1
204
2/15/2012 3:04:06 AM


For Windows:

  • From a powershell console opened as admin, 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
2018/02/13

On a Windows platform running Visual Studio 2015 RC (v4.6.00057) in combination with SourceTree (v1.6.14.0) will give this error as well.

Solution: Assuming you want to use source tree as source code manager, simply disable the source control provider inside Visual Studio like this:

  1. Go to: Tools > Options > Source Control
  2. Select Current source control plug-in as: None
2015/05/13

  1. check if the git still running (ps -ef | grep git)
  2. if not, remove the locked file
  3. if yes, kill the git process at first.
2013/04/15

try

rm -f ./.git/index.lock

if you have no other git process running, then just delete the index.lock file of the respective project.

2018/09/10

Just had this issue... Gitbox was at fault. So maybe you had a GUI running that was causing problems.

2012/02/16

Source: https://stackoverflow.com/questions/9282632
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]