【发布时间】:2016-12-15 23:39:49
【问题描述】:
对此有一段时间感到困惑,这是一个代表问题的提炼脚本:
#start
# note that master does not exist, so this should fail, would like to exit on the next line
git branch -D master || (echo "no master branch" && exit 1);
git fetch origin &&
git checkout master &&
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "master" ]]; then
echo 'Aborting script because you are not on the right git branch (master).';
exit 1;
fi
echo "done"
#end
当我运行上面的脚本时,我得到这个输出:
error: branch 'master' not found.
no master branch
error: Your local changes to the following files would be overwritten by checkout:
publish-to-NPM.sh
Please, commit your changes or stash them before you can switch branches.
Aborting
Aborting script because you are not on the right git branch (master).
请注意,“完成”不会得到回显,因此脚本会在第二次 exit 1 调用时退出。但是为什么脚本在第一次 exit 1 调用时不退出呢?对此感到非常困惑。
【问题讨论】:
-
看起来这可能会回答这个问题 - stackoverflow.com/questions/3822621/…