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 18.104.22.168
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 may be an old reply but I'm hoping this is more useful on next who need this solution.
On linux/unix/gitbash/cygwin, try
rm -f .git/index.lock
On Windows Command Prompt, try:
Read more... Read less...
- 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
On a Windows platform running Visual Studio 2015 RC (v4.6.00057) in combination with SourceTree (v22.214.171.124) 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:
- Go to: Tools > Options > Source Control
- Select Current source control plug-in as: None
- check if the git still running (ps -ef | grep git)
- if not, remove the locked file
- if yes, kill the git process at first.
rm -f ./.git/index.lock
if you have no other git process running, then just delete the index.lock file of the respective project.
Just had this issue... Gitbox was at fault. So maybe you had a GUI running that was causing problems.