git 在 WSL2 环境中推送在写入对象步骤中挂起

git push in WSL2 environment hang up during Writing Objects step

症状

我在 WSL2 环境中有一个 git 工作区。工作区位于 /mnt/c/workspace/repo 下,从 Windows 也可以通过路径 C:\workspace\repo 看到.

当我在工作区中从 WSL2 端执行 git 推送时,Git 挂断并显示此消息。

Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 16 threads
Compressing objects: 100% (24/24), done.
Writing objects:  34% (9/26)

这是在此上下文中观察到的其他行为和环境信息。

环境信息

$ git config --global --list
user.email=<my mail address>
user.name=<my name>
http.postbuffer=524288000

已尝试解决方法

配置中http.postBuffer

git config --global http.postBuffer 524288000

我在 Whosebug 的不同问题中遵循了这个答案。

此解决方法对我不起作用。

Windows 权限改变 attrib -r +s

我已按照此解决方法解决了 Windows 方面的一些权限问题。

attrib -r +s C:\workspace\repo

此解决方法对我不起作用。

尝试了 sudo git push

我试过 sudo git push 以防 git 命令无法访问某些锁定文件。

sudo GIT_SSH_COMMAND='ssh -i /home/<username>/.ssh/id_rsa' git push origin master

此解决方法对我不起作用。

使用https推送

错误消息已更改。但是这个解决方法对我不起作用。

$ git push --set-upstream origin master -vvvv
Pushing to https://github.com/kyasbal-1994/<repo-name>.git
Enumerating objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 16 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (26/26), 5.53 MiB | 7.42 MiB/s, done.
Total 26 (delta 6), reused 0 (delta 0)
POST git-receive-pack (5802813 bytes)
error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: CANCEL (err 8)
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
Everything up-to-date

您是否尝试过使用 Windows git.exe 的路径从 WSL 调用 Windows' git?事实上,您可以在 .bashrc:

中设置一个别名
alias wgit='/mnt/c/path\ to\ git/Git/git.exe`

这样,你就有了一个处理 Windows 文件的 Windows 可执行文件,而不是处理 Windows 文件的 Linux 可执行文件,虽然我有点模糊关于如何使用安装。

但是,我不确定输入路径时这对用户的友好程度如何。

假设可行,甚至可能有一种方法可以在 bash 中编写一个智能包装函数来检测存储库所在的文件系统并调用正确的 git 可执行文件...

作为替代方案,您可能更幸运地维护 2 个单独的存储库(WSL 和 Windows),然后通过 push/pulls 从服务器同步。