除非详细,否则使用ssh remote的git push会失败

时间:2014-12-11 12:29:37

标签: git ssh

我有一个git(版本2.1.2)存储库,其中包含ssh个遥控器:

$ git remote -v
origin  ssh://dettorer@dettorer.net:/home/dettorer/my_project (fetch)
origin  ssh://dettorer@dettorer.net:/home/dettorer/my_project (push)

未能推动:

$ git push
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

除非......我使用--verbose开关:

$ git push --verbose
Pushing to ssh://dettorer@dettorer.net:/home/dettorer/my_project
Enter passphrase for key '/home/dettorer/.ssh/id_rsa': 
Counting objects: 7, done.
...
To ssh://dettorer@dettorer.net:/home/dettorer/my_project
   e633fe9..5d2e9de  master -> master
updating local tracking ref 'refs/remotes/origin/master'

我将ssh日志级别增加为提示in that answer,但git push(不包含--verbose)的输出完全相同。

它可能来自哪里?

正如nwinkler建议的那样,这是两个带GIT_TRACE=2的命令的输出:

$ GIT_TRACE=2 git push
13:42:33.002392 git.c:349               trace: built-in: git 'push'
13:42:33.033594 run-command.c:341       trace: run_command: 'ssh' '-p' '' 'dettorer@dettorer.net' 'git-receive-pack '\''/home/dettorer/my_project'\'''
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

$ GIT_TRACE=2 git push -v
13:42:39.929236 git.c:349               trace: built-in: git 'push' '-v'
Pushing to ssh://dettorer@dettorer.net:/home/dettorer/my_project
13:42:39.944837 run-command.c:341       trace: run_command: 'ssh' 'dettorer@dettorer.net' 'git-receive-pack '\''/home/dettorer/my_project'\'''
Enter passphrase for key '/home/dettorer/.ssh/id_rsa':

因此,除非我使用--verbose,否则确实会有一个带有空参数的额外'-p'选项。

编辑:这变得越来越模糊:

$ git push origin
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git remote add test test
$ git push origin
Enter passphrase for key '/home/dettorer/.ssh/id_rsa': 

$ git remote remove test
$ git push origin
Bad port ''
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

2 个答案:

答案 0 :(得分:8)

好的,看到你的评论后,我很确定我知道什么是错的。

您可以尝试将远程网址更改为:

ssh://dettorer@dettorer.net/home/dettorer/my_project

你那里有一个额外的冒号,这似乎导致了额外端口的问题。我不知道为什么用-v运行它来修复问题。

git帮助显示以下是ssh协议支持的格式:

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

如您所见,只有在需要设置端口时才需要冒号。如果要使用标准端口,请将其关闭。

答案 1 :(得分:2)

注意:使用Git 2。3。7(2015年4月27日发布),此错误“Bad port ''”已不复存在。

请参阅commit ad34ad6commit 6b6c5f7Torsten Bögershausen tboegi

  

connect.c:忽略主机名

后的额外冒号      

忽略URL中主机名末尾的额外“:”   “ssh://example.com:/path/to/repo

     

冒号用于将端口号与主机名分开   如果端口为空,则应忽略冒号,请参阅RFC 3986。

     

它一直在使用ssh://方案的网址,但无意中   在86ceb3, "allow ssh://user@[2001:db8::1]/repo.git"中打破(Git 2.3.4)。

相关问题