Git“实时服务器”最佳实践

发布于 2024-10-28 08:23:14 字数 142 浏览 4 评论 0原文

我和我的合作伙伴一直在尝试从影响公众可查看的文件的存储库中推送和拉取的想法,而不是将存储库存储在隐藏位置,并在我们认为文件可以使用时仅通过 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 技术交流群。

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

发布评论

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

评论(4

玉环 2024-11-04 08:23:14

如果走这条路,我建议拉而不是推。

始终拉取成品,不要在实时服务器上进行合并,因为如果存在冲突,您将忙于修复它们。在您的测试环境中进行所有合并等。一旦一切顺利,将完成的结果推送到生产分支的“裸”存储库,然后从生产机器中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.

对岸观火 2024-11-04 08:23:14

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.

栩栩如生 2024-11-04 08:23:14

听起来您是脚本部署的候选人。我强烈建议研究 CapistranoWebistrano。使用这些工具,您可以轻松地从公开可用的 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.

つ可否回来 2024-11-04 08:23:14

我用这种方式将本地开发“推送”到 Live Server:

1.- 在服务器上配置一个钩子
.git/hooks/post-receive
包括以下几行:

     git pull
     git reset --hard

警告:重置--hard将删除实时工作区上的任何更改。 (见下文)

2.- 赋予文件可执行权限

 chmod +x .git/hooks/post-receive

3.- 允许实时服务器上的“非裸”存储库接收推送

 git config receive.denyCurrentBranch ignore

我在本地副本上工作(用于开发),该副本是直接从实时克隆的服务器。
并部署

 git push 

为了避免冲突,我有以下约定:
始终先拉再推
切勿在实时站点上工作或在服务器上提交。

我希望你觉得这个方法很有用。

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:

     git pull
     git reset --hard

Warning: reset --hard will remove any changes on the live workspace. (See below)

2.- Give Executable rights to the file

 chmod +x .git/hooks/post-receive

3.- Allow the "non-bare" repository on the live server to receive the Push

 git config receive.denyCurrentBranch ignore

I work on my local copy (for development), which was cloned directly from the live server.
and deploy by just

 git push 

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.

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