git push ...致命:无法创建master.lock:文件存在 [英] git push... fatal: Unable to create master.lock: File exists

查看:338
本文介绍了git push ...致命:无法创建master.lock:文件存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助!当我现在尝试执行git push origin master时,我得到:

Help! When I try to do a git push origin master now, I get:

fatal: Unable to create '/home/ubuntu/workspace/.git/refs/remotes/origin/master.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

当然,我发现了其他类似的问题(例如

Of course, I've found other similar questions (e.g. here), but the upvoted answers in there merely suggest deleting the offending file... but the file does not exist!

我担心这种情况是在我最近尝试使用以下方法清除一些空间之后发生的:

I fear that this is happening after I recently tried to clear some space using the following:

$ sudo git reflog expire --all --expire=now
$ sudo git gc --prune=now --aggressive

可能是原因吗?有修复建议吗?

Could that be the cause? Any suggestions for a fix?

推荐答案

该问题似乎源于以超级用户(sudo ...)身份运行到期代码.当Git调整了远程跟踪分支文件时,它们成为超级用户的所有权(因此只能由超级用户调整).

The problem appears to have stemmed from running the expiration code as the super-user (sudo ...). When Git adjusted the remote-tracking branch files, they became owned by (and hence only adjustable by) the super-user.

解决方法是将这些文件放回正确的所有者(在本例中为ubuntu).可以使用一揽子所有权更改(例如sudo chown -R ubuntu .git)或选择性的所有权更改(仅更改错误拥有的文件)作为根用户(或再次使用sudo),因为管道)find .git -user root -print0 | xargs -0 chown ubuntu.它们之间的唯一区别(如果有的话)是chown -R可能会更新更多文件的ctime(inode更改时间)字段(通过对已完全拥有的文件实际运行chown系统调用),这又可以影响备份系统.

The fix is to put those files back to the correct owner (in this case ubuntu). One can use a blanket ownership-change, e.g., sudo chown -R ubuntu .git, or a selective one (change only mis-owned files), e.g., as root (or with sudo again, this one is a bit more annoying because of the pipeline) find .git -user root -print0 | xargs -0 chown ubuntu. The only difference, if any, between these would be that chown -R might update more files' ctime (inode-change time) fields (by actually running chown system calls on files already properly owned), which can in turn affect backup systems.

更通用的规则是不要在sudo前面随意添加内容" –在这种情况下,没有理由将sudo放在git reflog expiregit gc命令的前面.

The more general rule is "don't arbitrarily prefix stuff with sudo"—in this case, there was no reason to put sudo in front of the git reflog expire and git gc commands.

这篇关于git push ...致命:无法创建master.lock:文件存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆