git拉取代码后,通过脚本检测代码是否为最新
#!/bin/bash
set -x
if [[ ${GIT_BRANCH} == origin/master ]]; then
echo -e "\033[32m正在部署分支: ${GIT_BRANCH}\033[0m"
git checkout master
exit 0
fi
commit_id=` git rev-parse refs/remotes/origin/master^{commit}`
if [[ ` git log | grep ${commit_id} |wc -l` -ge 1 ]]; then
echo -e "\033[32m正在部署分支: ${GIT_BRANCH}, 当前分支已包含origin/master最新代码\033[0m"
git checkout master
git pull
git merge ${GIT_BRANCH}
git push -u origin master
exit 0
else
echo -e "\033[31m正在部署分支: ${GIT_BRANCH}, 当前分支未包含origin/master最新代码,通知RD合并最新origin/master代码\033[0m"
exit 1
fi
![](https://www.wmmzz.com/wp-content/uploads/2021/02/image-47-1024x387.png)