以下是我执行一系列git操作的批处理脚本,如何在出现git错误(例如在git checkout时出现“分支已存在”)时使其失败?
``` ```
``` ```
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%
set ret = git checkout -b tmp %arg1%
echo %ret%
set ret = git checkout -b tmp %arg1%
echo %ret%
exit 0
REM emitted code for brevity
``` output :
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.
GIT
输出的,因为你展示的代码从未执行过GIT
。此外,你的SET
命令是不正确的。你需要在=
符号前后删除空格。 - Squashmanset ret = git checkout....
没有做任何事情..我正在纠正..谢谢 - old-monk