如题,在:
/home/git/taobao.git/hooks/post-update
这个 hook 里面如何获取当前推送的分支名呢?
我现在写的代码如下:
#!/bin/bash
#当前分支名
#branch=$(git rev-parse --abbrev-ref HEAD)
branch=$(git branch --show-current)
unset GIT_DIR
echo -e "branch-$branch"
if [[ $branch == "test" ]]; then
cd /home/www/taobaoTest
git reset --hard origin
/home/yhm/bash/pub 41
elif [[ $branch == "master" ]]; then
cd /home/www/taobao
git reset --hard origin
/home/yhm/bash/pub 4
fi
为何我在 test 分支上 push 代码获取到的 branch 也是 master 了呢?
这个可以不
在服务端 Git Hooks 中,你可以使用 $GIT_REF 环境变量来获取当前推送的分支名