Git 根据推送的分支自动从中央存储库推送到开发和生产
我对 Git 只是有点陌生,我只将它用于具有简单设置的基本项目。现在我正在努力思考一个更复杂的设置。我整晚都在谷歌搜索,但找不到任何与我想要如何设置相关的内容。
我的网络上有三台服务器:一台用于开发 (dev.example.com),一台用于生产 (www.example.com),另一台充当两者之间的中心阶段 (central.example.com)。
我想在 Central 上创建一个主(可能是裸)Git 存储库,我可以从本地计算机(与三个主服务器分开,但位于同一网络上)推送到该存储库。理想情况下,该存储库将有两个分支:master 和 Development。我的本地机器只会处理 Central 上的这个存储库。
当我推送到 Central 上的开发分支时,Central 应该将这些更改推送到 DEV 服务器。同样,对 master 分支的更改应该推送到 WWW。我认为使用提交/更新挂钩将是实现此目标的最佳方法。
这是一个粗略绘制的图表:
Local
|
Central
/ \
DEV WWW
有人能指出我正确的方向吗?谢谢!
I am somewhat new to Git only and I have only used it for basic projects with simple setups. Now I am struggling to wrap my head around a more complex setup. I have been up all night Googling but I can't find anything related to how I want to set this up.
I have three servers on my network: one for development (dev.example.com), one for production (www.example.com), and another that acts a central stage between the two (central.example.com).
I want to create a main (probably bare) Git repository on Central that I can push to from my local machine (which is separate from the three main servers but on the same network). Ideally, this repo would have two branches: master and Development. My local machine will only deal with this repo on Central.
When I push to the dev branch on Central, Central should then push those changes to the DEV server. Likewise, changes to the master branch should be pushed to WWW. I think using a commit/update hook would be the best way to accomplish this.
Here is a crudely drawn diagram:
Local
|
Central
/ \
DEV WWW
Could someone kindly point me in the right direction? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须使用
post-update
或post-receive
挂钩;它们是在推送到存储库完成后运行的。他们之间唯一的区别是他们如何获得论据。我建议对生产/登台服务器使用 ssh 触发器,然后从那里运行拉取,因为:
ssh 触发器是一个脚本,与 ssh 中的特定公钥相关联(在
.ssh/authorized_keys
中的公钥前面加上command=
trigger)。当您使用该密钥通过 ssh 登录时,ssh 将忽略客户端提供的命令并运行触发器。这限制了有人窃取密钥时可能造成的损害,因为触发器可以使用它自己的逻辑来知道要做什么,并且不接受来自客户端的任何输入。或者,您可以简单地推动并安装适当的挂钩来检查。请参阅这个问题< /a>.
You have to use
post-update
orpost-receive
hook; they are the ones that run after push to the repository completes. The only difference between them is how they get the arguments.Than I'd suggest using an ssh trigger to the production/staging server tu run a pull from there, because:
An ssh trigger is a script, that is associated with particular public key in ssh (prefix the public key in
.ssh/authorized_keys
withcommand=
trigger). When you log in with ssh using that key, ssh will ignore command provided by client and run the trigger. This limits possible damage when somebody steals the key, because the trigger can use it's own logic to know what to do and not accept any input from the client.Alternatively you can simply push and install appropriate hook to check out. See this question.
你可以在 Git 中设置钩子来轻松获得你想要的东西。利用 post-receive 钩子,它从标准输入接收以下内容:
示例:
aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
使用
refname
,您可以在脚本中查看正在推送的分支to 并依次推至适当的回购协议 - www 或 dev。或者,您可以使用
post-update
钩子,它仅接收引用名称,也可以作为参数来执行相同的操作。为了完整起见,该钩子必须放置在中央存储库的钩子中。
You can setup hooks in Git to easily get what you want here. Make use of post-receive hook, which receives the following from stdin:
<oldrev> <newrev> <refname>
Example:
aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
Using the
refname
you can see in your script what branch is being pushed to and inturn push to the appropriate repo - www or dev.Or, you can use the
post-update
hook which receives only refname and also as an argument to do the same thing.For sake of completeness, the hook must be placed in the hooks of the Central repo.