每个分支的 Git 提交挂钩
我正在努力学习 git 的一些更高级的用法,我认为 hooks 是我想要的方式,也许有人可以在这里给我一些建议。
我的计划是拥有一个包含 3 个分支(开发、登台和生产)的 git 存储库。我希望提交这 3 个分支中的每一个,以在提交后触发不同的脚本。
git 有能力做到这一点还是我找错了树?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在提交后挂钩中,您可以执行以下操作:
In a post-commit hook you could do the following:
我为自己编写了一个脚本来执行此功能。
https://github.com/fotuzlab/githubdump-php
将此文件托管在您的服务器上,最好是 repo root 并在 github webhooks 中定义 url。将第 8 行的“allcommits”更改为您的分支名称,并在第 18 行添加您的代码/函数。
您的所有 3 个实例将需要单独的文件和 Webhook。
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.
Simon Boison 示例的轻量级替代方案:
A lightweight alternative to Simon Boison's example: