应该如何(以及在​​哪里)定义一个钩子来自动将网站上传到生产环境?

发布于 2024-11-18 16:10:20 字数 227 浏览 5 评论 0原文

我有一个中央服务器作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好倦 2024-11-25 16:10:20

您的问题不太清楚,需要有关您的设置的更多详细信息。

如果您想拉入生产服务器(或从中央服务器推送到生产服务器),并且您使用的是 updatepost-receive更新后,仅当您提交到稳定分支时,您才可以轻松地pullpush

以中央服务器上的 update 挂钩为例,它需要三个参数:

- the name of the ref being updated,
- the old object name stored in the ref,
- and the new objectname to be stored in the ref.

通过检查引用的名称是否是您想要的(稳定),然后执行 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 or post-update, you can easily make them pull or push only if you commit to the stable branch.

Taking the specific example of an update hook on the central server, it takes three parameters:

- the name of the ref being updated,
- the old object name stored in the ref,
- and the new objectname to be stored in the ref.

By checking the name of the ref to be what you want( stable ) and then doing a push or pull to the production server will help you achieve the selective update that you want.

http://git-scm.com/docs/githooks

半步萧音过轻尘 2024-11-25 16:10:20

您无法推送到生产服务器,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文