Git“实时服务器”最佳实践
我和我的合作伙伴一直在尝试从影响公众可查看的文件的存储库中推送和拉取的想法,而不是将存储库存储在隐藏位置,并在我们认为文件可以使用时仅通过 FTP 传输文件。虽然能够直接推送到“实时站点”将非常方便,但我想知道这会产生什么负面影响(如果有的话)。
多谢!
My partner and I have been dabbling with the idea of pushing and pulling from a repo that affects files viewable by the general public as opposed to storing the repos in a hidden location and just FTPing files when we feel they're good to go. While being able to directly push to the "live site" would be extremely convenient, I'm wondering what negative repercussions (if any) this would incur.
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果走这条路,我建议拉而不是推。
始终拉取成品,不要在实时服务器上进行合并,因为如果存在冲突,您将忙于修复它们。在您的测试环境中进行所有合并等。一旦一切顺利,将完成的结果推送到生产分支的“裸”存储库,然后从生产机器中
git pull
。是的,这可能是另一个失败点,但我认为利大于弊。
I would recommend pulling rather than pushing if going this route.
Always pull the finished product and do not do merges on the live server, for if there are conflicts you will be scrambling to fix them. Do all your merging, etc on your testing environment. Once all is good there, push the finished results to your 'bare' repo for the production branch and then from the production machine
git pull
from it.Yes it could be another point of failure however I think the benefits outway the cons.
VCS 不应该是部署工具(请参阅 使用git 在生产中的 Web 根目录下。):一个文件的简单 ftp(使用
git archive
创建)就足够了。如果您想使用 Git,请在服务器端使用裸存储库进行推送,并使用
post-receive
钩子来更新代表您网站的工作树。A VCS isn't supposed to be a deployment tool (see Using git below web root in production.): a simple ftp of one file (created with
git archive
) would be enough.If you want to use Git, use a bare repo on the server side to push to, and a
post-receive
hook to update a working tree which would represent your site.听起来您是脚本部署的候选人。我强烈建议研究 Capistrano 和 Webistrano。使用这些工具,您可以轻松地从公开可用的 git 存储库进行部署,并仅更新服务器上所需的代码。存储库的缓存副本保存在服务器上,因此您仅传输更改集。我提到的两个工具还允许您轻松回滚更改、管理数据库迁移等。Webistrano 本质上是 Capistrano 的 Web 前端,Capistrano 是一个 ruby gem。我也听说过关于弗拉德的好消息,但我不太熟悉。祝你好运。
It sounds like you are a candidate for scripted deployments. I would highly suggest looking into Capistrano and Webistrano. With these tools, you can deploy from a publicly available git repo easily and update only the code necessary on the server. A cached copy of the repo is held on the server, so you are only transmitting the change sets. The two tools I mentioned also allow you to easily roll back changes, manage database migrations, etc. Webistrano is essentially a web front-end to Capistrano, which is a ruby gem. I've also heard good things about Vlad, but I'm not as familiar with it. Best of luck.
我用这种方式将本地开发“推送”到 Live Server:
1.- 在服务器上配置一个钩子
.git/hooks/post-receive
包括以下几行:
警告:重置--hard将删除实时工作区上的任何更改。 (见下文)
2.- 赋予文件可执行权限
3.- 允许实时服务器上的“非裸”存储库接收推送
我在本地副本上工作(用于开发),该副本是直接从实时克隆的服务器。
并部署
为了避免冲突,我有以下约定:
始终先拉再推
切勿在实时站点上工作或在服务器上提交。
我希望你觉得这个方法很有用。
I "Push" my local development to the Live Server this way:
1.- Configure a hook on the server
.git/hooks/post-receive
including this lines:
Warning: reset --hard will remove any changes on the live workspace. (See below)
2.- Give Executable rights to the file
3.- Allow the "non-bare" repository on the live server to receive the Push
I work on my local copy (for development), which was cloned directly from the live server.
and deploy by just
In order to avoid conflicts I have the convention of:
Always Pull before pushing
Never work on the live site or commit on the server.
I hope you find this method useful.