在 Windows 版 Git 中使用 GIT_SSH_COMMAND
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31475646/
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
Using GIT_SSH_COMMAND in Git for Windows
提问by Victor N
I'm using Fourth release candidate of Git for Windows 2.x now, and using GIT_SSH_COMMAND in shell to avoid SSH's host verification. In Git Bash I write something like this:
我现在正在使用适用于 Windows 2.x 的 Git 的第四个候选版本,并在 shell 中使用 GIT_SSH_COMMAND 以避免 SSH 的主机验证。在 Git Bash 中,我写了这样的东西:
$ GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git push origin master
How can I do something like this in Windows cmd? Can't find any answers anywhere.
我怎样才能在 Windows cmd 中做这样的事情?在任何地方都找不到任何答案。
回答by VonC
You don't have to set an environment variable anymore in Windows.
您不必再在 Windows 中设置环境变量。
With git 2.10+ (Q3 2016), you also have the possibility to set a configfor GIT_SSH_COMMAND
, which is easier than an environment variable (and can be set globally, or locally for a specific repo)
使用Git 2.10+(Q3 2016),你也必须设置一个可能配置的GIT_SSH_COMMAND
,这比一个环境变量容易(可以设置全局或局部特定回购)
See commit 3c8ede3(26 Jun 2016) by Nguy?n Thái Ng?c Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
--in commit dc21164, 19 Jul 2016)
参见Nguy?n Thái Ng?c Duy ( ) 的commit 3c8ede3(26 Jun 2016 )。(由Junio C Hamano合并-- --在dc21164 提交中,2016 年 7 月 19 日)pclouds
gitster
A new configuration variable
core.sshCommand
has been added to specify what value for GIT_SSH_COMMAND to use per repository.
添加了一个新的配置变量
core.sshCommand
来指定每个存储库使用的 GIT_SSH_COMMAND 值。
core.sshCommand:
If this variable is set,
git fetch
andgit push
will use the specified command instead ofssh
when they need to connect to a remote system.
The command is in the same form as theGIT_SSH_COMMAND
environment variable and is overridden when the environment variable is set.
如果这个变量被设置,
git fetch
并且git push
将使用指定的命令而不是ssh
当它们需要连接到远程系统时。
该命令与GIT_SSH_COMMAND
环境变量的形式相同,并在设置环境变量时被覆盖。
It means the git push
can be:
这意味着git push
可以是:
cd /path/to/my/repo
git config core.sshCommand 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
# later on
git push origin master
With Git 2.16 (Q1 2018), you will have a new mechanism to upgrade the wire protocol in place is proposed and demonstrated that it works with the older versions of Git without harming them.
使用 Git 2.16(2018 年第一季度),您将拥有一种新机制来升级有线协议,并证明它可以与旧版本的 Git 一起使用而不会损害它们。
See commit 6464679(16 Oct 2017), and commit 0cd8328(26 Sep 2017) by Jonathan Tan (jhowtan
).
See commit 94b8ae5, commit 3c88ebd, commit 19113a2, commit 0c2f0d2, commit 2609043, commit aa9bab2, commit dfe422d, commit 373d70e, commit 5d2124b(16 Oct 2017) by Brandon Williams (mbrandonw
).
(Merged by Junio C Hamano -- gitster
--in commit 4c6dad0, 06 Dec 2017)
见犯6464679(二零一七年十月一十六日),并提交0cd8328(2017年9月26日)由乔纳森·谭(jhowtan
)。
见提交94b8ae5,提交3c88ebd,提交19113a2,提交0c2f0d2,提交2609043,提交aa9bab2,提交dfe422d,提交373d70e,提交5d2124b(2017年10月16日),由布兰登·威廉姆斯(mbrandonw
)。
(由Junio C gitster
Hamano合并-- --在4c6dad0 提交中,2017 年 12 月 6 日)
ssh
: introduce a 'simple
' ssh variantWhen using the '
ssh
' transport, the '-o
' option is used to specify an environment variable which should be set on the remote end.
This allows Git to send additional information when contacting the server, requesting the use of a different protocol version via the 'GIT_PROTOCOL
' environment variable like so: "-o SendEnv=GIT_PROTOCOL
".Unfortunately not all ssh variants support the sending of environment variables to the remote end.
To account for this, only use the '-o
' option for ssh variants which are OpenSSH compliant.
This is done by checking that the basename of the ssh command is 'ssh
' or the ssh variant is overridden to be 'ssh
' (via thessh.variant
config).Other options like '
-p
' and '-P
', which are used to specify a specific port to use, or '-4
' and '-6
', which are used to indicate that IPV4 or IPV6 addresses should be used, may also not be supported by all ssh variants.Currently if an ssh command's basename wasn't '
plink
' or 'tortoiseplink
', Git assumes that the command is an OpenSSH variant.
Since user configured ssh commands may not be OpenSSH compliant, tighten this constraint and assume a variant of 'simple
' if the basename of the command doesn't match the variants known to Git.
The new ssh variant 'simple
' will only have the host and command to execute ([username@]host
command) passed as parameters to thessh
command.
ssh
: 引入一个 'simple
' ssh 变体使用“
ssh
”传输时,“-o
”选项用于指定应在远程端设置的环境变量。
这允许 Git 在联系服务器时发送附加信息,通过 'GIT_PROTOCOL
' 环境变量请求使用不同的协议版本,如下所示:“-o SendEnv=GIT_PROTOCOL
”。不幸的是,并非所有 ssh 变体都支持将环境变量发送到远程端。
为了解决这个问题,请仅对-o
符合 OpenSSH 的 ssh 变体使用“ ”选项。
这是通过检查 ssh 命令的基本名称是否为“ssh
”或 ssh 变体是否被覆盖为“ssh
”(通过ssh.variant
配置)来完成的。像“其他选项
-p
”和“-P
”,这是用来指定一个特定的端口来使用,或“-4
”和“-6
”,这是用来表明,IPv4或IPv6地址应该被使用,也并非所有的SSH变体支持.当前,如果 ssh 命令的基本名称不是“
plink
”或“tortoiseplink
”,Git 会假定该命令是 OpenSSH 变体。
由于用户配置的 ssh 命令可能与 OpenSSH 不兼容,因此simple
如果命令的基本名称与 Git 已知的变体不匹配,请收紧此约束并假设为“ ”的变体。
新的 ssh 变体“simple
”将仅将主机和要执行的[username@]host
命令( command) 作为参数传递给ssh
命令。
回答by Victor N
Here is the answer:
这是答案:
set GIT_SSH_COMMAND=ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no & git push origin master