代码之家  ›  专栏  ›  技术社区  ›  unhammer

如何通过ssh从Windows计算机Git克隆?

  •  1
  • unhammer  · 技术社区  · 6 年前

    我能做到 ssh windowsmachine 从Linux访问Windows机器,从那里我可以 git init --bare foo.git 告诉我 Initialized empty Git repository in C:/Users/unhammer/foo.git/

    但是如何从Unix端克隆它呢?

    $ git clone ssh://windowsmachine:foo.git
    Cloning into 'foo'...
    fatal: No path specified. See 'man git-pull' for valid url syntax
    
    $ git clone ssh://windowsmachine:C:\\Users\\unhammer\\foo.git
    Cloning into '\Users\unhammer\foo'...
    fatal: No path specified. See 'man git-pull' for valid url syntax
    
    $ git clone ssh://windowsmachine:/foo.git
    Cloning into 'foo'...
    fatal: ''/foo.git'' does not appear to be a git repository
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    和类似的信息 /C:/Users/unhammer/foo.git /C/Users/unhammer/foo.git /Users/unhammer/foo.git .

    注意双引号:

    fatal: ''/Users/unhammer/foo.git'' does not appear to be a git repository
    

    当我尝试的时候不会发生这种情况 git clone linuxmachine:/some/path/that/does/not/exist.git ,然后Git使用单引号。(也许这就是问题所在,Git for Windows或其他应用额外报价的应用程序?)

    2 回复  |  直到 6 年前
        1
  •  0
  •   unhammer    6 年前

    跟随 @phd 的链接 https://stackoverflow.com/a/8050564/7976758 我找到一个参考 https://stackoverflow.com/a/2323826/69663 解决报价问题。我是这样做的:

    在Windows上,打开git bash,在my homedir中:

    echo 'git-receive-pack "$@"' >grp.sh
    echo 'git-upload-pack "$@"' >gup.sh
    

    在Linux上,克隆指定上载包:

    git clone -u '"C:/Program Files/Git/bin/bash.exe" gup.sh' ssh://windowsmachine/c/Users/unhammer/foo.git
    cd foo
    git config remote.origin.uploadpack '"C:\Program Files\Git\bin\bash.exe" gup.sh'
    git config remote.origin.receivepack '"C:\Program Files\Git\bin\bash.exe" grp.sh'
    

    所以回购路径就是GitBash显示的路径( /c/Users/$username/$repo )任何地方都没有结肠。


    https://github.com/PowerShell/Win32-OpenSSH/issues/1082 似乎是相关的。

        2
  •  0
  •   unhammer    6 年前

    最简单的解决办法是 change the default Windows OpenSSH shell to bash .您可以通过Windows计算机上的PowerShell轻松完成此操作:

    powershell
    New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\bash.exe" -PropertyType String -Force
    

    您可能需要在Windows计算机上重新启动openssh,和/或在客户端上终止现有的ssh连接,然后才能生效。现在您可以克隆而不需要任何额外的-u选项:

    git clone ssh://windowsmachine/c/Users/unhammer/foo.git
    

    (如果之前指定了uploadpack/receivepack,请将其从.git/config中删除)

    推荐文章