Git push ERROR: Unable to create '.git/refs/remotes/jr/master.lock': File exists

Git push ERROR: Unable to create '.git/refs/remotes/jr/master.lock': File exists

这不是重复的。我查看了 this stack overflow post and this post 并尝试了他们的解决方案,但没有用。

我正在使用 Ubuntu 16.04 并尝试将项目推送到 Github。

当我运行:

git push jr master

我收到这个错误:

error: update_ref failed for ref 'refs/remotes/jr/master': cannot lock
ref 'refs/remotes/jr/master': Unable to create 
'/home/john/Desktop/john-rykken-V2/.git/refs/remotes/jr/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.
Everything up-to-date

我有 运行 以下命令:

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

都没用。我也重新启动了我的机器和 运行 ps -a | grep git,但没有找到任何 运行ning 进程。最后,当我进入我的项目目录并手动搜索 master.lock 时,我找不到它。

建议?我的下一步是重新克隆存储库。

您可能 运行 一个带有 sudo 的 git 命令,这导致您的 .git 存储库中的一些文件归 root 所有。尝试 运行使用此命令将存储库中所有文件的所有权更改为您的用户:

sudo chown -R john /home/john/Desktop/john-rykken-V2/.git

我在这里假设您正在尝试与用户 john 运行 git。否则,将其更改为正确的用户。

编辑:

事实证明,必须删除错误消息中的文件: rm -f .git/refs/remotes/jr/master.lock