git push ...致命:无法创建master.lock:文件存在

时间:2016-05-07 18:31:43

标签: git repository

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

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.

当然,我发现了其他类似的问题(例如here),但其中的upvoted答案仅建议删除有问题的文件......但该文件不存在!

我担心在我最近尝试使用以下内容清除空间后会发生这种情况:

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

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

1 个答案:

答案 0 :(得分:4)

问题似乎源于以超级用户(sudo ...)身份运行过期代码。当Git调整远程跟踪分支文件时,它们由超级用户拥有(因此只能由其调整)。

修复方法是将这些文件放回正确的所有者(在本例中为ubuntu)。可以使用全局所有权更改,例如sudo chown -R ubuntu .git,或选择性更改(仅更改错误拥有的文件),例如,作为root(或再次使用sudo,这个更多一点由于管道而烦恼{} {}。这些之间唯一的区别(如果有的话)是find .git -user root -print0 | xargs -0 chown ubuntu可能会更新更多文件'chown -R(inode-change time)字段(通过对已正确拥有的文件实际运行ctime系统调用),这反过来会影响备份系统。

更一般的规则是“不要随意chown添加内容” - 在这种情况下,没有理由将sudo放在sudo和{{ 1}}命令。