我正在寻找获得最后一次提交的分支的方式,现在我正在做类似的事情
last_co_branch=$(git branch --sort=-committerdate| head -1| grep -o -e "develop" -e "master")
if [[ "$last_co_branch" == "master" ]]; then
# stuff ...
fi
if [[ "$last_co_branch" == "develop" ]]; then
# stuff ...
fi
但它看起来很奇怪。
答案 0 :(得分:1)
你可以这样做:
last_co_branch=$(git for-each-ref --count=1 --sort=-committerdate refs/heads/ --format='%(refname:short)')
if [[ "$last_co_branch" == "master" ]]; then
# stuff ...
fi
if [[ "$last_co_branch" == "develop" ]]; then
# stuff ...
fi