问题
I am getting the following error while pushing the commit
$ git push origin master
fatal: unable to create 'refs/heads/master.lock': File exists fatal:
The remote end hung up unexpectedly
I thought of removing the lock file (refs/heads/master.lock
) from my local machine. But this file is not available. I think this file is in git server.
What is the origin of this issue? If I remove this file from the server, will it solve the issue if the file exists?
回答1:
You need to remove existing .lock
file and try to push,
Linux
rm -f .git/refs/heads/master.lock
Windows
del .git\refs\heads\master.lock
回答2:
It is because some other git operation might have died ( or even still running in the rare ) in the middle and left a lock file. Once you see that no git related process is running on the server, just to be safe, you can delete the file and try to push again.
回答3:
For those who come to this page with this problem but can't use the accepted solution because the file doesn't exist to be deleted, it's probably a permissions issue.
This SO question should be helpful. In my case I had been working with both root and a normal user account on different terminals and must have done something as root and caused problems like is suggested in the linked answers. Solution was to fix permissions in my git directory back to the user.
回答4:
I just used 'sudo' before my commit and it worked. I.e. "sudo git commit -am'commit message'"
来源:https://stackoverflow.com/questions/8500089/fatal-unable-to-create-refs-heads-master-lock-file-exists-fatal-getting-t