应该如何(以及在哪里)定义一个钩子来自动将网站上传到生产环境?
我有一个中央服务器作为 git 服务器,我从另一台电脑推送我的更改。我也与另一位开发人员同时工作。他在 git 服务器中准备了一个钩子,这样当我们推送它时,它就会拉取任何更改。
我们现在想做的就是从生产服务器中获取。我们使用两个主要分支(主分支和稳定分支),因此当我们决定将某些内容提交为稳定分支时,我们希望生产服务器以任何方式拉取它。我不太确定是否可以按需拉动,但我几乎没有找到有关这方面的信息。你有什么想法吗?提前致谢。
I have a central server acting as a git server, and I push my changes from another pc. I work in parallel with another developer, too. He prepared a hook in the git server so when we pushed it pulls any change.
What we would want to do now is to also pull from a production server. We work with two main branches (master and stable), so when we decide to commit something as stable, we would like the production server to pull it in any way. I'm not plenty sure if it is possible to pull on demand, but I have found little to no information about this aspect. Do you have any idea? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题不太清楚,需要有关您的设置的更多详细信息。
如果您想拉入生产服务器(或从中央服务器推送到生产服务器),并且您使用的是
update
、post-receive
或更新后
,仅当您提交到稳定分支时,您才可以轻松地pull
或push
。以中央服务器上的
update
挂钩为例,它需要三个参数:通过检查引用的名称是否是您想要的(稳定),然后执行
push 或
pull
到生产服务器将帮助您实现所需的选择性更新。http://git-scm.com/docs/githooks
Your question is not exactly clear and requires more details on your setup.
If you want to pull in your production server ( or push to your production server from the central server ), and if you are using a hook like
update
,post-receive
orpost-update
, you can easily make thempull
orpush
only if you commit to the stable branch.Taking the specific example of an
update
hook on the central server, it takes three parameters:By checking the name of the ref to be what you want( stable ) and then doing a
push
orpull
to the production server will help you achieve the selective update that you want.http://git-scm.com/docs/githooks
您无法推送到生产服务器,因为 a) 默认情况下 git 不会推送到非裸存储库,b) 如果您强制它,它只能更新存储库,而不能更新工作目录。您必须进入生产存储库目录并从那里提取。您可以使用中央存储库上的接收后挂钩来自动执行此操作,并且您应该准备好处理文件所有权问题。
You can't push to the production server because a) by default git won't push to a non-bare repository, and b) if you force it, it can only update the repo, not the working directory. You have to get into the production repository directory and pull from there. You could automate that with a post-receive hook on the central repo, and you should be prepared to deal with file ownership issues.