每个分支Git提交挂钩 [英] Git commit hooks per branch

查看:124
本文介绍了每个分支Git提交挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究更高级的git用法,我认为hook是我想要去的方式,也许有人可以给我一些建议。

I'm working on getting into some more advanced usage of git, and I think hooks are the way that I want to go, perhaps somebody can give me some advice here.

我的计划是拥有一个包含3个分支(开发,分段和生产)的git存储库。我希望对这3个分支中的每一个提交触发一个不同的脚本post-commit。

My plan is to have a git repository with 3 branches (development, staging, and production). I want commits to each of these 3 branches to trigger a different script post-commit.

git是否有能力做到这一点,还是我吠叫错误的树?

Does git have the capability to do this or am I barking up the wrong tree?

预先感谢。

推荐答案

你可以做到以下几点:

if [ `git rev-parse --abbrev-ref HEAD` == "development" ]; then
   echo "development-script"
elif [ `git rev-parse --abbrev-ref HEAD` == "staging" ]; then
   echo "staging-script"
elif [ `git rev-parse --abbrev-ref HEAD` == "production" ]; then
   echo "production-script"
fi

这篇关于每个分支Git提交挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆