【问题标题】:Why do Git commands fail via Win32-OpenSSH on Windows 10?为什么 Git 命令在 Windows 10 上通过 Win32-OpenSSH 失败?
【发布时间】:2018-07-14 04:23:32
【问题描述】:

我在 Windows 10 系统上设置了 Win32-OpenSSH,并且我正在使用 Git for Windows 2.16.1。
我创建了一个裸测试存储库,我可以通过文件 URL 从中很好地克隆:

git clone file:///c:/test.git
Cloning into 'test'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 33 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (33/33), done.
Resolving deltas: 100% (11/11), done.

SSHD 也运行良好,我可以从平板电脑打开一个 shell,并通过 SFTP 访问存储库目录:

> sftp oli@localhost
oli@localhost's password:
Connected to oli@localhost.
sftp> pwd
Remote working directory: /C:/Users/Oli
sftp> cd /c:/test.git
sftp> pwd
Remote working directory: /c:/test.git
sftp> ls
HEAD  config  description  hooks  info  objects  packed-refs  refs
sftp> bye

但是由于某种原因,通过 SSH 克隆失败:

> git clone ssh://oli@localhost:22/c:/test.git
Cloning into 'test'...
oli@localhost's password:
fatal: ''/c:/test.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.

用户“Oli”肯定拥有正确的访问权限,我们在上面已经看到存储库存在并且是一个有效的 Git 存储库。我还在路径上尝试了许多不同的语法变体。
我已经阅读了关于 Git/SSH/Windows 的所有问答、Git Pro 书籍、Git 参考、OpenSSH 手册和 Win32-OpenSSH wiki。

我错过了什么?

【问题讨论】:

  • 这里有什么帮助吗? stackoverflow.com/questions/1092583/…
  • 是的!解决方案在 Konstantin 给出的答案中:问题是 - cmd.exe 不理解单引号参数。按照他的建议使用自定义上传命令时,克隆终于起作用了。

标签: windows git ssh


【解决方案1】:

this question 中的Konstantin 已对此进行了回答(感谢您提供链接,Aurel):

问题是 - cmd.exe 不理解单引号参数。

Git 将存储库的路径用单引号括起来,这在 cmd.exe 中不起作用。
这实际上可以在上面的 Git 错误消息中看到,如果你看得足够近的话:

fatal: ''/c:/test.git'' does not appear to be a git repository

所以我设置了康斯坦丁建议的解决方法:

  • 在服务器上我的主目录中创建 shell 脚本 gup.sh 和 grp.sh,每个都包含单行 git-upload-pack.exe $* 和。 git-receive-pack.exe $*
  • 在初始克隆操作中使用参数 -u 'sh gup.sh'(在 cmd.exe 中执行此操作时,使用双引号...)
  • 使用命令git config remote.origin.uploadpack 'sh gup.sh'git config remote.origin.receivepack 'sh grp.sh'配置克隆存储库

...它的工作原理。

可悲的是,康斯坦丁的答案不是被接受的答案,也是最不受欢迎的答案。因此,如果这对您也有帮助,请点赞他的回答!

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 2017-09-25
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多