You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git连接字符串ssh://与git@格式的差异及克隆失败问题排查

两种Git SSH克隆命令的差异解析

这两种SSH风格的Git克隆命令核心差异在于路径解析逻辑,结合你使用的git-server-docker镜像配置,具体原因如下:

1. 完整SSH URL格式(可正常执行)

git clone ssh://git@localhost/git-server/repos/my_repo.git

这种格式是标准的SSH URL写法,冒号:之后的/git-server/repos/my_repo.git会被解析为服务器(容器)文件系统的绝对路径,正好匹配你挂载的/git-server/repos目录,所以Git能正确找到仓库文件。

2. SSH简写格式(执行失败)

git clone git@localhost:git-server/repos/my_repo.git

这种简写格式是Git对SSH地址的语法糖,冒号:之后的路径默认被解析为相对于git用户家目录的相对路径。
对于你使用的git-server-docker镜像,git用户的默认家目录是/home/git,而非/git-server。所以Git会尝试访问/home/git/git-server/repos/my_repo.git,这个路径并不存在,因此抛出仓库不存在的错误。

如何让简写格式生效

如果想使用简写格式克隆,需要在路径前添加斜杠,强制Git将其解析为绝对路径:

git clone git@localhost:/git-server/repos/my_repo.git

内容的提问来源于stack exchange,提问作者Stephan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 00:55:21