Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在批处理脚本中使用git命令时,如何在出错时失败?_Git_Batch File - Fatal编程技术网

在批处理脚本中使用git命令时,如何在出错时失败?

在批处理脚本中使用git命令时,如何在出错时失败?,git,batch-file,Git,Batch File,下面是我在其中执行一组git操作的批处理脚本,如何在git签出“分支已存在”之类的git错误上失败 ``` ``` 输出: c:\my-project>c:\bat\git-copy-branch.bat master my-git-branch c:\my-project>git checkout -b tmp master fatal: A branch named 'tmp' already exists. c:\my-project>git checkout -b

下面是我在其中执行一组git操作的批处理脚本,如何在git签出“分支已存在”之类的git错误上失败

```

``` 输出:

c:\my-project>c:\bat\git-copy-branch.bat master my-git-branch

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.

:Quit
是一个标签<代码>如果错误级别1检查前一个命令中是否有任何错误;它确实检查errorlevel>=1。

我不确定您如何获得任何
GIT
输出,因为您显示的代码从不执行
GIT
。您的
SET
命令也不正确。您需要删除
=
符号前后的空格。@Squashman oops。。。尴尬那是我一直在尝试的。。您是对的set cmd
set ret=git checkout什么都不要做。。。我正在改正。。谢谢
c:\my-project>c:\bat\git-copy-branch.bat master my-git-branch

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.

c:\my-project>git checkout -b tmp master
fatal: A branch named 'tmp' already exists.
REM arg 1 = branch to copy
REM arg 2 = branch in which copy will be merged
set arg1=%1%
set arg2=%2%
echo copying %arg1% to %arg2%
echo "check out as tmp "+%arg1%
git checkout -b tmp %arg1%
if errorlevel 1 goto Quit
echo Ok
git checkout -b tmp %arg1%
if errorlevel 1 goto Quit
echo Ok
:Quit