.bat脚本中的git clone

时间:2016-09-06 12:37:37

标签: git batch-file

是否可以编写一个执行" git clone"的Windows .bat脚本。在脚本中间,以便脚本继续?它总是让我退出。

我正在使用来自" Git开发社区的64位Git版本2.8.3"在Windows 7 Enterprise SP1上。 git.exe在我的路径中(c:\ program files \ git \ cmd \ git.exe) - 它不是通过git.cmd或类似文件间接执行的。

我可以运行一系列命令,如

git init
git add --all
git commit -m "commit message"

并使用这些命令,批处理脚本执行每个命令正常继续。随着

git clone {url}

脚本立即退出,通常带有双倍提示,表示某种异常退出(即使%ERRORLEVEL%为0):

git clone {url} new
Cloning into 'new'...
remote: Counting objects: 26, done
remote: Compressing objects: 100% (23/23) done.
remote: Total 26 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (26/26) done.
Checking connectivity... done.
c:\jdev\ppss\finalprep\ant2>c:\jdev\ppss\finalprep>

常见的Windows技巧,​​如使用"调用git clone ......"和" cmd / c git clone ..."似乎没有工作。甚至"启动/等待cmd / c git clone ..."没有做到。

有什么想法吗?

2 个答案:

答案 0 :(得分:2)

" git clone"之后的行是一份IF声明:

git clone {url} subfolder
if "%var%" == "y" (
  @echo some commands went here
) else (
  @echo different commands went here
}

上述IF语句不是合法的DOS if语句(错误的ELSE关闭),但是你没有从DOS获得任何错误消息 - 你的脚本只是退出。看起来上一个命令导致中止,在我的情况下碰巧是git clone。

这与git无关,严格来说是cmd.exe废话。

答案 1 :(得分:1)

在失败的特定情况下," git clone"的子目录写作已经存在,因为先前的" mkdir"。如果没有mkdir - 没有子网已经存在 - 批处理脚本在git clone正常后继续,并且不需要像cmd / c这样的特殊技巧