Git忽略了配置文件中的core.sshcommand,但使用GIT_SSH_COMMAND命令正常工作。

4

我希望使用配置文件来设置sshCommand而不是环境变量。但是似乎不起作用。以下是具体情况:

➜  GIT_SSH_COMMAND='ssh -i /var/www/level2.lu/www/git_id_rsa -F /dev/null' git ls-remote 
From git@github.com:syn2cat/Level2.lu.git
fcaa5a2e63499568dd916e7b18f950b311781bd0    HEAD
fcaa5a2e63499568dd916e7b18f950b311781bd0    refs/heads/master
a542061a64d3698d5da54d63456b26932fe549a2    refs/pull/1/head

➜  git config core.sshcommand                                                           
ssh -i /var/www/level2.lu/www/git_id_rsa -F /dev/null
➜  git ls-remote
Permission denied (publickey).
fatal: Could not read from remote repository.

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

关于调试,它不使用核心的sshCommand值。

 GIT_TRACE=1 git ls-remote 
13:46:15.366401 git.c:344               trace: built-in: git 'ls-remote'
13:46:15.366564 run-command.c:334       trace: run_command: 'ssh' 'git@github.com' 'git-upload-pack '\''syn2cat/Level2.lu.git'\'''

版本

➜  lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial
➜  git --version
git version 2.7.4
1个回答

10

Git 2.10.0版本中新增了core.sshCommand选项。由于您的Git版本是2.7.4,没有这个功能。如果您想使用它,您需要升级到更新的Git版本。


2
我尝试了使用export GIT_SSH_COMMANDENV方法和使用git config --global core.sshCommand的配置方法,但都失败了。原来我使用的docker镜像是基于debian/jessie的,它只有git 2.1版本。我在错误的地方进行故障排除花费了数小时!感谢@brian。 - user3905644
设置环境变量 GIT_TRACE=1 将显示 git 调用的 ssh 命令。 - Marco Aurelio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接