在批处理脚本中使用git命令时,如何在出错时失败?
下面是我在其中执行一组git操作的批处理脚本,如何在git签出“分支已存在”之类的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
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 cmdset 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