Ben*_*bin 8 git visual-studio visual-studio-2019
我可以在命令行中使用 Git 推送到 Github,没有任何问题。现在我正在尝试使用 Visual Studio 2019 推送到 Github。我在 Visual Studio 中打开“Git”>“管理分支”窗口,然后单击当前提交上的“推送”链接。我收到以下错误:
Opening repositories:
C:\Users\brubin\source\repos\MyRepo
Commit 6da600da created locally in repository C:\Users\brubin\source\repos\MyRepo
Pushing master
Pushing to github.com:MyUser/MyRepo.git
Error: cannot spawn C:/WINDOWS/System32/OpenSSH/ssh.exe: No such file or directory
Error encountered while pushing to the remote repository: Git failed with a fatal error.
unable to fork
Failed to push to the remote repository. See the Output window for more details.
Run Code Online (Sandbox Code Playgroud)
ssh.exe 确实存在于该路径上。我也尝试过以管理员身份运行 Visual Studio。
core.sshCommand设置Visual Studio 2019 将尝试该core.sshCommand设置。对于我来说,这也默认为 32 位 ssh 客户端C:\Windows\System32\。
我成功更改了配置,如下所示。打开命令提示符并更改您选择的 ssh 可执行文件的路径 - 在我的例子中,它是来自 Windows 的 Git 版本。
git config --global core.sshCommand "\"C:\Program Files\Git\usr\bin\ssh.exe\""
是的,包括"然后转义\",否则会因为空格而误读设置,并且错误消息可能会显示C:\Program 找不到或类似的内容。
然后可以在您的主目录中的文件中找到该设置.gitconfig。
我想我已经成功解决了这里的问题,同时仍然使用OpenSSH. 内置的Windows 10OpenSSH是64位程序。但是从 Visual Studio 中运行的 Git 是 32 位的。Visual Studio使用其中的一个C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin"(根据您的VS版本调整路径)。
问题是,Windows 使用虚拟文件夹来阻止 32 位程序访问 64 位库。因此,如果 32 位应用程序尝试访问System32文件夹,它将被重定向到SysWOW64。那里没有OpenSSH。OpenSSH您可以通过尝试从32-bitpowershell 窗口访问文件夹来模拟:
> cd C:\Windows\System32\OpenSSH\
Run Code Online (Sandbox Code Playgroud)
你想要做的就是设置GIT_SSH为
C:\Windows\SysNative\OpenSSH\ssh.exe
Run Code Online (Sandbox Code Playgroud)
SysNative 是一个虚拟文件夹,它实际上并不存在于您的系统上。但是通过访问它,程序不会被重定向到SysWOW64
| 归档时间: |
|
| 查看次数: |
5123 次 |
| 最近记录: |