VSCode git error: fatal: failed to read object XXX: The remote end hung up unexpectedly fatal: error: failed to push

VSCode git error: fatal: failed to read object XXX: The remote end hung up unexpectedly fatal: error: failed to push

我厌倦了在 windows 10 WSL1 上将新分支推送到 github,git 2.17.1。我当时摸索着密码提示,但它超时了。当我再次尝试时,至少挂断一次后,我现在收到此错误消息:

Pushing to https://github.com/repo/project
fatal: failed to read object <hash>: Permission denied
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'https://github.com/repo/project'

如何撤消此操作,以便再次推送?

此消息表示由于权限问题,Git 需要推送的对象之一无法读取。

如果这些文件在您的 WSL 主目录下,请考虑尝试 运行 对您的文件进行 chmodchown 之类的操作,以便可以访问它们。您可以 运行 find .git -ls 显示文件的所有者和权限。目录需要具有您的用户的读取和执行权限,文件需要具有读取权限。

如果您正在寻找一种直截了当的方法,您可以这样做(用您的用户代替 bk2204):

$ sudo chown -R bk2204: .git
$ chmod -R u+rwX .git

如果这是一个 Windows 目录,那么事情就有点棘手了。您需要使用正常的 Windows 权限机制来修改内容。如果您尝试将供 WSL 使用的文件存储在特殊的 Windows 目录之一中,例如 Documents,请不要:Windows 限制许多程序(包括 WSL 的部分或全部)对这些文件的访问,并且将需要由 WSL 访问的东西存储在那里只会导致问题。