Git URI 与 SSH URI 规范不匹配

Git URIs does not match SSH URI specification

我正在研究 SSH URI specification 以便更多地了解 URL 用于通过 SSH 访问 Github 或 Bitbucket 等服务中的存储库。

一个典型的 SSH Github URL 看起来像这样:git@github.com:myuser/myrepo.git,我认为可以分解为以下部分:

   scheme           authority
     |                 |
    /‾‾\/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\
    ssh://git@github.com:myuser/myrepo.git
          \_/ \________/ \_______________/
           |      |              |
          user   host           port

我不明白的是端口部分。 official general URI specification states that ports should contain only numeric values. The SSH URI scheme specification sticks to the general URI specification. And the OpenSSH config manual 做同样的事情。

那为什么他们在端口部分使用类似路径的文本?这是否偏离了事实上已经确立的标准?还是我理解错了这整件事?

如果有人能澄清这一点,我将不胜感激。

Git repos 可以不仅仅使用 URI 来引用。例如,您可以使用路径,并且您可以使用 ssh command 将采用的大部分(可能是全部,尚未检查)的东西。 ssh 命令也不需要 ssh URI:它已经知道它是解释资源标识符的那个,所以对 uniform 资源标识符施加的限制没有任何要添加的值在这里,跟随他们没有任何收获

Git 接受存储库标识符的完整语法可以在 git clone 文档中找到,在 GIT URLS.

TL:DR 问题中描述的语法是一个名为 rcp 的旧程序的继承,不符合 URI 规范。

说明

感谢@jthill 和@torek 为我指明了正确的方向。经过几天的研究,这是我的猜测。

OpenSSH 中的所有三个远程操作程序(sshscpsftp)接受符合 SSH URI 方案的参数,在其自己的 IETF specification.

从广义上讲,任何 URI 都由五个部分组成:方案、权限、路径、查询和片段。此外,权限可以由用户信息、主机和端口组成。对于SSH URI方案,只允许方案、权限和路径。

   scheme     authority           path
     |           |                 |
    /‾‾\/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\
    ssh://git@github.com:22/myuser/myrepo.git
          \_/\_________/\_/
           |      |      |
          user   host   port

但是,有一种替代语法与标准 SSH URI 方案非常相似,但并不完全符合它。此语法是 1981 年创建的旧 rcp(远程复制)程序的遗产,几乎比 URI 协议创建早了十五年。当 Berkeley r-commands were released, to specify the destination of an operation in rsh (remote shell) or rlogin (remote login) it was only required to specify the remote machine in which the operation was going to be performed, and probably the user in that machine as well. At that time, the consensus was the syntax username@hostname. The rcp program, however, had an additional condition, given that in order to copy files from, or to, one remote location, the developer was required to specify the path of the file in that remote machine, in addition to the user and host, just as the cp program does. The syntax they come across was to append the path to the end of the user/host declaration, separated by a colon: username@hostname:path/to/file (as described in its own manpage).

    git@github.com:myuser/myrepo.git
    \_/ \________/ \_______________/
     |      |              |
    user   host           path

当 OpenSSH 团队实施 scp 程序时,他们想为已经在使用 rcp 的开发人员提供熟悉的 API,因此他们决定继续支持这个旧的,自定义语法,以及新的标准化 SSH URI 方案。然后,在 2005 年 Git 进入了对 SSH 的原生支持,可能在幕后使用了 OpenSSH,并且当 SSH 用于clonefetchpushpull 等远程操作。 Git 文档将此语法称为 scp-like 语法 ,并在 scp manpage, the git-clone docs, and the Git protocols docs 中对其进行了简要描述。最后,尽管缺乏标准化,它似乎是所有云 Git 服务(如 Github 或 Bitbucket)在提供​​ URL 用于克隆回购协议时使用的语法。