git 致命:无法创建“refs/heads/master.lock”:文件存在致命:-推送提交时出现此错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8500089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:29:45  来源:igfitidea点击:

fatal: unable to create 'refs/heads/master.lock': File exists fatal: - Getting this error while pushing the commits

gitgit-push

提问by Jon

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.

我想refs/heads/master.lock从本地机器上删除锁定文件 ( )。但是这个文件不可用。我认为这个文件在 git 服务器中。

What is the origin of this issue? If I remove this file from the server, will it solve the issue if the file exists?

这个问题的根源是什么?如果我从服务器中删除此文件,如果该文件存在,它会解决问题吗?

回答by Jay Patel

You need to remove existing .lockfile and try to push,

您需要删除现有.lock文件并尝试推送,

Linux

Linux

rm -f .git/refs/heads/master.lock

Windows

视窗

del .git\refs\heads\master.lock

回答by manojlds

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.

这是因为其他一些 git 操作可能在中间已经死亡(甚至仍然在罕见的运行)并留下一个锁文件。一旦你看到服务器上没有运行任何与 git 相关的进程,为了安全起见,你可以删除文件并再次尝试推送。

回答by I_dont_remember

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 questionshould 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.

这个SO问题应该会有所帮助。就我而言,我一直在不同终端上使用 root 和普通用户帐户,并且必须以 root 身份执行某些操作并导致问题,例如链接答案中建议的问题。解决方案是将我的 git 目录中的权限修复回用户。

回答by Margaret

I just used 'sudo' before my commit and it worked. I.e. "sudo git commit -am'commit message'"

我只是在提交之前使用了“sudo”并且它起作用了。即“sudo git commit -am'commit message'”