git 使用具有非标准端口的远程存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1558719/
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-10 07:12:33  来源:igfitidea点击:

Using a remote repository with non-standard port

git

提问by brainfck

I am setting up my local git project for a remote repository. The remote repository is being served on a non-standard port (4019).

我正在为远程存储库设置我的本地 git 项目。远程存储库在非标准端口 (4019) 上提供服务。

But it doesn't work. Instead I get the following error message:

但它不起作用。相反,我收到以下错误消息:

ssh: connect to host git.host.de:4019 port 22: Connection refused
fatal: The remote end hung up unexpectedly
error: failed to push to 'ssh://[email protected]:4019/var/cache/git/project.git'

My local git config is as follows:

我的本地 git 配置如下

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = ssh://[email protected]:4019/var/cache/git/project.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master

(The port and host are placeholders for the actual port and host.)

(端口和主机是实际端口和主机的占位符。)

What is wrong with my git configuration?

我的 git 配置有什么问题?

采纳答案by CB Bailey

If you put something like this in your .ssh/config:

如果你把这样的东西放在你的.ssh/config

Host githost
HostName git.host.de
Port 4019
User root

then you should be able to use the basic syntax:

那么你应该能够使用基本语法:

git push githost:/var/cache/git/project.git master

回答by jdpf

SSH based git access method can be specified in <repo_path>/.git/configusing either a full URL or an SCP-like syntax, as specified in http://git-scm.com/docs/git-clone:

可以<repo_path>/.git/config使用完整 URL 或类似 SCP 的语法指定基于 SSH 的 git 访问方法,如http://git-scm.com/docs/git-clone 中所述

URL style:

网址样式:

url = ssh://[user@]host.xz[:port]/path/to/repo.git/

SCP style:

SCP风格:

url = [user@]host.xz:path/to/repo.git/

Notice that the SCP style does not allow a direct port change, relying instead on an ssh_confighost definition in your ~/.ssh/configsuch as:

请注意,SCP 样式不允许直接更改端口,而是依赖ssh_config于您的主机定义,~/.ssh/config例如:

Host my_git_host
HostName git.some.host.org
Port 24589
User not_a_root_user

Then you can test in a shell with:

然后你可以在 shell 中测试:

ssh my_git_host

and alter your SCP-style URI in <repo_path>/.git/configas:

并将您的 SCP 样式 URI 更改<repo_path>/.git/config为:

url = my_git_host:path/to/repo.git/

回答by Ricky

Try this

尝试这个

git clone ssh://[email protected]:11111/home/git/repo.git

回答by Peter

This avoids your problem rather than fixing it directly, but I'd recommend adding a ~/.ssh/configfile and having something like this

这避免了您的问题,而不是直接修复它,但我建议添加一个~/.ssh/config文件并使用类似的内容

Host git_host
HostName git.host.de
User root
Port 4019

then you can have

那么你可以拥有

url = git_host:/var/cache/git/project.git

and you can also ssh git_hostand scp git_host ...and everything will work out.

你也可以ssh git_hostscp git_host ...一切都会好起来的。

回答by Greg Hewgill

SSH doesn't use the :syntax when specifying a port. The easiest way to do this is to edit your ~/.ssh/configfile and add:

SSH:在指定端口时不使用该语法。最简单的方法是编辑您的~/.ssh/config文件并添加:

Host git.host.de
  Port 4019

Then specify just git.host.dewithout a port number.

然后只指定git.host.de不带端口号。