Git commit hooks per branch

百般思念 提交于 2019-11-27 12:11:49

问题


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.

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.

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

Thanks in advance.


回答1:


in a post-commit hook you could do the following:

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



回答2:


I had written a script for myself to do this functionality.

https://github.com/fotuzlab/githubdump-php

Host this file on your server, preferably repo root and define the url in github webhooks. Change 'allcommits' on line 8 with your branch name and add your code/function at line 18.

You will need separate files and webhooks for all your 3 instances.

Hope this helps!



来源:https://stackoverflow.com/questions/6372334/git-commit-hooks-per-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!