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

Det*_*rer 6 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)
Run Code Online (Sandbox Code Playgroud)

哪个没能推:

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

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

除非......我使用--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'
Run Code Online (Sandbox Code Playgroud)

在该答案中ssh提示增加了日志级别,但(没有)的输出完全相同.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':
Run Code Online (Sandbox Code Playgroud)

因此,除非我使用--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.
Run Code Online (Sandbox Code Playgroud)

nwi*_*ler 9

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

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

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

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

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

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

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

  • 它甚至可以正常工作`-v`并忽略空端口.可能是在详细模式下使用不同的url解析器. (2认同)