帮助!当我尝试做一个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 https://stackoverflow.com/questions/9282632/git-index-lock-file-exists-when-i-try-to-commit-but-cannot-delete-the-file),但那里的赞成答案只是建议删除有问题的文件......但该文件不存在!
我担心这种情况是在我最近尝试使用以下方法清理一些空间后发生的:
$ sudo git reflog expire --all --expire=now
$ sudo git gc --prune=now --aggressive
这可能是原因吗?有修复建议吗?
该问题似乎源于以超级用户身份运行过期代码(sudo ...
)。当 Git 调整远程跟踪分支文件时,它们将归超级用户所有(因此只能由超级用户调整)。
解决方法是将这些文件放回正确的所有者(在本例中ubuntu
)。人们可以使用一揽子所有权变更,例如,sudo chown -R ubuntu .git
,或选择性的一个(仅更改错误拥有的文件),例如,作为root(或使用sudo
再次,由于管道的原因,这个有点烦人)find .git -user root -print0 | xargs -0 chown ubuntu
。它们之间唯一的区别(如果有的话)是chown -R
可能会更新更多文件'ctime
(inode-change time)字段(通过实际运行chown
系统调用已经正确拥有的文件),这反过来又会影响备份系统。
更一般的规则是“不要随意在东西前面加上前缀sudo
“——在这种情况下,没有理由放sudo
在......面前git reflog expire
and git gc
命令。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)