简体   繁体   English

git clone silent不起作用

[英]git clone silent doesn't work

I am trying to clone a repo automatically from a .bat file. 我试图从.bat文件自动克隆一个repo。

I use ssh so the .bat file first moves a " id_rsa " file to the " user\\.ssh " folder. 我使用ssh,因此.bat文件首先将“ id_rsa ”文件移动到“ user\\.ssh ”文件夹。

Then, when I run " git clone ssh://repo c:\\repo ", I get the question 然后,当我运行“ git clone ssh://repo c:\\repo ”时,我得到了问题

The authenticity of host can't be established. 
RSA key fingerprint is ........ 
Are you sure you want to continue connecting (yes/no)?

If I answer yes manually it works and the " known_hosts " file is created in " user\\.ssh " folder. 如果我手动回答是,它可以工作,并且“ known_hosts ”文件在“ user\\.ssh ”文件夹中创建。 Now if I run the .bat file the git clone will work without the question. 现在,如果我运行.bat文件, git clone将无问题地运行。

I need to do this silently from the .bat file. 我需要从.bat文件中静默地执行此操作。
I have tried to answer yes from the .bat file and to add " > /dev/nul 2>&1 " but with no success. 我试图从.bat文件中回答“ yes ”并添加“ > /dev/nul 2>&1 ”,但没有成功。

Any ideas? 有任何想法吗?

You should try and adapt " Can I automatically add a new host to known_hosts? " in order to add the remote server to your %USERPROFILE%\\.ssh\\known_hosts . 您应该尝试调整“ 我可以自动将新主机添加到known_hosts吗? ”,以便将远程服务器添加到%USERPROFILE%\\.ssh\\known_hosts

Even from your Windows bat script, you can use a /path/to/git/bin/bash -c '...' command. 即使从Windows bat脚本,您也可以使用/ path / to / git / bin / bash -c'...'命令。

c:\path\to\git\bin\bash -c 'ssh-keyscan -t rsa,dsa HOST 2>&1 | sort -u - ~/.ssh/known_hosts > ~/.ssh/tmp_hosts && mv ~/.ssh/tmp_hosts ~/.ssh/known_hosts'

That allows you to use linux commands like grep, sort, ... which are part of the git distribution. 这允许你使用像grep,sort,...这样的linux命令,它们是git发行版的一部分。

Are you using an updated bash?. 你在使用更新的bash吗? Essentially what you're doing here is redirect to /dev/null, which is "nowhere". 基本上你在这里做的是重定向到/ dev / null,这是“无处”。 If you want to do it silently you can try git clone git@gitlab.com:username/repo directory -q 如果你想静静地做,你可以尝试git clone git@gitlab.com:username / repo directory -q

为了使它工作,至少现在,我从另一台服务器下载known_hosts文件和id_rsa。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM