通过 ssh 从 stash 克隆 git-repository

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18952795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:06:02  来源:igfitidea点击:

cloning git-repository from stash via ssh

gitsshbitbucket-server

提问by Vince

I've got a git-repository running on a stash-server. Cloning the repository via httpworks fine

我有一个在 stash-server 上运行的 git-repository。通过http工作正常克隆存储库

git clone http://user@server:7990/a/b/sandbox.git

For some weird reason, when I switch httpwith sshand with it the port, it gives me

出于某种奇怪的原因,当我切换http使用ssh,并与它的端口,它给了我

git clone ssh://user@server:7999/a/b/sandbox.git
Cloning into sandbox...
fatal: remote error: Remote URL invalid
A repository could not be determined from the remote URL. Please confirm the
clone URL in Stash and try again. URL suffix: '/scm/ct/sandbox.git'
fatal: The remote end hung up unexpectedly

The server has sshenabled and the port set to 7999. How comes, that it can't find the repository when the request is sent via sshrather than http?

服务器已ssh启用且端口设置为7999。当请求通过ssh而不是发送时,它怎么找不到存储库http

回答by Vince

Problem solved. For some reason, the SSH-URL-suffix for the repository is different from the HTTP-URL-suffix. After finding that out, it worked.

问题解决了。出于某种原因,存储库的 SSH-URL-suffix 与 HTTP-URL-suffix 不同。发现后,它起作用了。

Edit:
The http-url stash gave me was user@server:7990/a/b/sandbox.git, while the ssh-url stash gave me is user@server:7999/b/sandbox.git(where a and b are of course placeholders).

编辑:
http-url stash 给我的是user@server:7990/a/b/sandbox.git,而 ssh-url stash 给我的是user@server:7999/b/sandbox.git(其中 a 和 b 当然是占位符)。

As it was mentioned in the comments, that I should add this to my answer.

正如评论中提到的那样,我应该将其添加到我的答案中。

回答by AD7six

Configure ssh to do it for you

配置 ssh 为您完成

Unless it's desirable to write out explicitly the clone url (e.g. cloning is performed by a parameterized script) it's generally easier to configure ssh so that it understands what servermeans and therefore the command arguments are just the defaults you'd normally expect. So for example in your ssh config fileput:

除非需要明确写出克隆 url(例如,克隆由参数化脚本执行),否则配置 ssh 通常更容易,以便它了解server含义,因此命令参数只是您通常期望的默认值。例如,在您的ssh 配置文件中输入

Host server
  User user
  Port 7999

Which then permits:

然后允许:

$ git clone server:/a/b/sandbox.git

In this way, and especially if there are multiple repositories on the git server, it means you don′t need to remember the more complex/explicit syntax to clone a repo.

通过这种方式,特别是如果 git 服务器上有多个存储库,这意味着您不需要记住更复杂/显式的语法来克隆一个存储库。