Visual Studio 2019 git 问题:在获取/推送时“无法生成... ssh.exe:没有这样的文件或目录”

dav*_*bak 8 git openssh visual-studio visual-studio-2019

无法让 VS2019 获取/推送到远程(恰好在 GitLab 上)。什么是正确的配置?

  1. 我正在使用内置的 Windows 10 OpenSSH ( C:\Windows\System32\OpenSSH)

  2. 我已经设置了环境变量GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

  3. 私钥ssh-agent通过加载到正在运行的服务中ssh-add

  4. 从普通的命令窗口(即不是 WSL bash shell)我可以按我的心高兴地推送/获取。

  5. 从 VS2019 开始,打开存储库 ( Git>Local Repositories>myrepo),当我尝试Git>FetchGit>Push在输出窗口中看到以下内容:

    Commit eebc0b4a created locally in repository r:\bbits\edu-bitcoin-staging
    Opening repositories:
    r:\bbits\edu-bitcoin-staging
    Pushing master
    Pushing to gitlab.com:bakins-bits/edu-bitcoin-staging.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.
    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)

请注意C:\Windows\System32\OpenSSH\ssh.exe: No such file or directory- 但这是正确的路径:

C:\>dir C:\Windows\System32\OpenSSH\ssh.exe
 Volume in drive C is P70-MSVC
 Volume Serial Number is 8240-9525

 Directory of C:\Windows\System32\OpenSSH

10/15/2019  06:50 AM           882,688 ssh.exe
               1 File(s)        882,688 bytes
               0 Dir(s)  333,358,600,192 bytes free
Run Code Online (Sandbox Code Playgroud)

51M*_*RGL 7

我想我已经成功解决了这里的问题。内置的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。那里没有OpenSSHOpenSSH您可以通过尝试从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


小智 5

用它来转义“程序文件”中的空间

git config --global core.sshCommand 'C:\\PROGRA~1\\\\Git\\usr\\bin\\ssh.exe'
Run Code Online (Sandbox Code Playgroud)


Von*_*onC 0

首先检查 VS2019 中的相同推/拉是否适用于在会话中启动的 VS2019,其中:

  • GIT_SSH未设置
  • ssh.exe%PATH%(意思是,在启动 VS2019 之前,应该先where ssh返回一个“” ,before )C:\Windows\System32\OpenSSH\ssh.exeC:\path\to\Git\usr\bin\ssh.exe

我不需要设置GIT_SSH这些操作即可工作。