从 bash 脚本中克隆 Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10857024/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:10:55  来源:igfitidea点击:

Git clone from bash script

gitbashsshgit-clone

提问by agatha

I am trying to automate my interactions with Git building a script and I am having the following problem.

我正在尝试自动与 Git 构建脚本的交互,但我遇到了以下问题。

This works from the command line:

这从命令行工作:

git clone [email protected]:blablabla/reponame.git /Users/myname/dev/myfolder

And now I would like to do the same, but from my script. I have the following:

现在我想做同样的事情,但来自我的脚本。我有以下几点:

#/bin/bash

repository="[email protected]:blablabla/reponame.git"

localFolder="/Users/myname/dev/myfolder"

git clone $repository" "$localFolder

that gives me this error

这给了我这个错误

GitHub SSH access is temporarily unavailable (0x09). fatal: The remote end hung up unexpectedly

GitHub SSH 访问暂时不可用 (0x09)。致命:远端意外挂断

Any light on this will be much appreciated

对此的任何了解都将不胜感激

回答by Charles Duffy

You mean git clone "$repository" "$localFolder", I'd hope?

你是说git clone "$repository" "$localFolder",我希望?

Running git clone $repository" "$localFolderis something quite different:

跑步git clone $repository" "$localFolder是完全不同的东西:

  • Because neither variable is within double quotes, their contents are string-split and glob-expanded; thus, if they contained whitespace (generally, characters within $IFS), they could become multiple arguments, and if they contained globs (*, [...], etc), those arguments could be replaced with filenames (or simply removed from the generated argument list, if the nullglobshell option is enabled)
  • Because the space between the two arguments is quoted, they are combined into a single argument before being passed to git.
  • 因为这两个变量都不在双引号内,所以它们的内容是字符串拆分和全局扩展的;因此,如果它们含有空格(通常,内的字符$IFS)时,它们可能成为多个参数,并且如果它们包含水珠(*[...]等),这些参数可以与文件名,代替(或简单地除去从所生成的参数列表,如果nullglob壳选项已启用)
  • 因为两个参数之间的空格被引用,所以它们在传递给 之前被组合成一个参数git

So, for the values you gave, what this script runs would be:

因此,对于您提供的值,此脚本运行的内容将是:

git clone "[email protected]:blablabla/reponame.git /Users/myname/dev/myfolder"

...which is quite different from

......这与完全不同

git clone [email protected]:blablabla/reponame.git /Users/myname/dev/myfolder

...as it is giving the /Users/myname/dev/myfolderpath as part of the URL.

...因为它将/Users/myname/dev/myfolder路径作为 URL 的一部分。