部署git分支 [英] Deploy git branches

查看:143
本文介绍了部署git分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用git进行web开发的工作流程之后,我的任务是在最后一秒添加一个登台服务器。我们在本地开发/测试并推出回购协议,现在需要有一个沙盒,以便其他部门的人员可以在不打破任何东西的情况下玩弄新东西。



远程仓库需要两个长期运行的分支(本着nvie分支模式的精神),掌握和开发。



我们需要能够推到一个repo,并将开发分支结帐到test.site.com docroot,当准备好时,合并开发成master和checkout master到site.com docroot



所以在服务器上...

  git init 
git add。
git commit -m初始提交
git checkout -bdevelop

在我们的本地机器上...

  git clone user@site.com:/repos/repo1.git 
???
git push origin / develop(???更新test.site.com docroot)

并返回到服务器进行代码生活

  git checkoutmaster
git merge develop(??? Updates site.com docroot)
git checkout -bdevelop

本地

  git pull 



<



编辑:
到目前为止,我正在试验一些答案。在过渡期间提出了一个完全黑客的想法,并认为我会分享:



一个后接收挂钩来统治它们。



我们克隆裸露的回购和追踪开发。推动发展/发展。

Post-receive - 将GIT_WORK_TREE设置为test.site.com,checkout -f开发

如果提交消息包含merge_master,将GIT_WORK_TREE设置为site.com docroot,

  git checkout master 
git merge develop
git checkout -f master(这将用于修补程序)

合并主开发人员当地的



在尘埃落定之后,发送含有difflog的电子邮件,拧紧双手并have一口劲。



有多少种不同的方式可以中断?

解决方案

在git中,您通常不会推送到具有结帐的存储库。完全一样。你可以推送到一个,但你不能推送到检出分支,但你通常不应该。主要是为了让事情明确分开,并避免在Web服务器崩溃并需要修复时中断中央存储库。



所以你应该有一个 bare (用于没有工作树的存储库的术语)中央存储库。每个人都将使用该存储库。它应该存在于你的内部网络上,不应该在公共服务器或测试服务器的文档根目录下。事实上,我强烈建议不要把它放在任何一台服务器上,而应该放在单独的(可能是虚拟的)机器上。



现在你有了Web服务器。它们可以是工作副本,也可以是使用 git archive 创建的导出,并且可以通过cron或 post-update hook在中央仓库中。



工作副本由更新 on site.com 服务器和 git pull central-repo-url develop on test.site .com 服务器(好的,在其他答案中建议的获取+重置可能会更好,因为您确定您没有任何更改)。



通过获取带有 git archive 的zip或tar包并将其解压缩来更新导出。这是一个更多的工作。



Cron定期运行命令。它更容易设置,但缺点是推送和服务器上显示的内容之间存在延迟。



post-update hook的设置比较复杂,但没有延迟(因为下载数据需要一些时间,所以显然会有一些延迟)。基本上你创建一个脚本来运行更新,可以通过服务器上的ssh或web请求触发。与在中央存储库中放置脚本 hooks / post-update 相比,这将触发服务器上的脚本。应该没有办法给他们任何参数,并且该机制出于安全原因不应允许运行除这些脚本之外的任何其他代码。您可以通过查看哪个分支被推送(请参阅git doc找到它的位置)并仅触发正确的服务器来使钩子更高级。



git push origin develop 会导致 test.site.com 被更新(但间接通过脚本)并且使代码生效你会做的(在开发机器上; 从来没有在服务器上工作!)



git checkout master
git merge develop
git push origin master


,最后一条命令会导致 site.com 被更新,脚本。


After struggling with and sorting out a workflow for web development with git, I've been tasked with adding in a staging server at the last second. We develop/test locally and push out to a repo, and now there needs to be a sandbox in between so people in other departments can play around and try out new things without breaking stuff.

Remote repo needs two long-running branches (in the spirit of nvie's branching model), master and develop.

We need to be able to push to one repo, and checkout the develop branch to test.site.com docroot, and when ready, merge develop into master and checkout master into site.com docroot

So on the server...

git init
git add .
git commit -m "Initial commit"
git checkout -b "develop"

And on our local machines...

git clone user@site.com:/repos/repo1.git
???
git push origin/develop (??? Updates test.site.com docroot)

And back to the server to make code live

git checkout "master"
git merge develop (??? Updates site.com docroot)
git checkout -b "develop"

And locally

git pull

Help with the question marks or alternative suggestions appreciated.

Edit: Am experimenting with some of the answers so far. Had come up with a completely hacky idea in the interim and thought I'd share:

One post-receive hook to rule them all.

We clone a bare repo and track develop. Push develop to origin/develop.

Post-receive - Set GIT_WORK_TREE to test.site.com, checkout -f develop

If the commit message contains "merge_master", sets GIT_WORK_TREE to site.com docroot,

git checkout master
git merge develop  
git checkout -f master (this would be for hotfixes)

Merge master back into develop and pull locally

After the dust settles, send email with difflog, wring your hands and have a sip of something strong.

How many different ways could that break?

解决方案

In git, you normally never push to repository that has checkout. At all. You can push to one except you can't push to the checked out branch, but you usually shouldn't. Mainly to keep things clearly separated and to avoid disrupting the central repository if the web server breaks and needs to be fixed up.

So you should have a bare (term used for repository without work tree) central repository. Everybody will be using that repository. It should live on your internal network and should not be in docroot of either public or test server. In fact I would strongly suggest not putting it on either server at all, but separate (possibly virtual) machine.

Now you have the web servers. They can be either working copies, or just exports created using git archive and can be updated either by cron, or post-update hook in the central repository.

Working copy is updated by git fetch central-repo-url master on site.com server and by git pull central-repo-url develop on test.site.com server (ok, the fetch + reset suggested in the other answer is probably better, because you are sure you don't have any changes there).

Export is updated by getting a zip or tar pack with git archive and extracting it. It's a bit more work.

Cron just runs the commands periodically. It's easier to set up, but the disadvantage is that there is a delay between push and the content appearing on the servers.

post-update hook is a more complicated to set up, but does not have that delay (there is obviously some delay since downloading the data takes some time too). Basically you create a script to run the update, that can be triggered either by ssh or web request on the servers. Than in the central repository you put script hooks/post-update, that will trigger the scripts on the servers. There should be no way to give them any parameters and the mechanism should not allow running any other code than those scripts for security reasons. You can make the hook more advanced by looking which branch was pushed (see git doc for where you find it) and triggering only the correct server.

Than git push origin develop will cause the test.site.com to be updated (but indirectly, via the scripts) and to make code live you'll do (on development machine; never work on server!)

git checkout master git merge develop git push origin master

and the last command will cause site.com to be updated, again indirectly via the scripts.

这篇关于部署git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆