使用 Heroku 的 Git 子模块
问题
我在 Heroku 上有一个 Rails 3.1 应用程序,它将很快需要一堆(第 3 方)子模块(其中一些有子模块)。不幸的是,Heroku 缺乏子模块支持。 Heroku 网站上的一项建议是将子模块的内容移至主存储库中(此处)。第一次可以正常工作,但第二次可能就不行了。这可能是由于第三方子模块之一的重大更新导致快进合并不成功。显然我们无法手动合并第三方项目。
“解决方案”
我们暂定的解决方案如下:
- 基于最新的稳定开发分支创建一个新的“temp”分支,并将子模块合并到项目中。
- 签出到
heroku
分支。 - 删除此
heroku
分支的内容以避免任何可能的冲突,即创建一个删除所有内容的提交。 - 将 temp 分支合并到
heroku
分支。 - 将此
heroku
分支推送到我们的 Heroku 服务器。
优点
这将避免第三方子模块中任何可能的冲突,并且可以编写脚本。
缺点
这是极其不优雅的,并且是 SVC 的最终反模式。
问题
有没有更好的方法来做到这一点?
The Problem
I have a Rails 3.1 app on Heroku which will soon require a bunch of (3rd party) submodules (some of which have submodules). Unfortunately, Heroku lacks submodule support. One suggestion on Heroku's website is to move the contents of the submodules into the main repo (here). This will work fine the first time, but there is a possibility that it won't the second. This could be caused by a major update in one of the third party submodules where a fast forward merge is unsuccessful. Obviously we can't manually merge a third party project.
The "Solution"
Our tentative solution is as follows:
- Create a new 'temp' branch based on the latest stable dev branch and merge the submodules into the project.
- Checkout to a
heroku
branch. - Nuke the contents of this
heroku
branch to avoid any possible conflicts, i.e. create a commit with everything deleted. - Merge the temp branch into the
heroku
branch. - Push this
heroku
branch to our Heroku server.
The Advantages
This will avoid any possible conflicts in third party submodules and is scriptable.
The Disadvantages
This is extremely inelegant and is the ultimate anti-pattern for SVC.
The Question
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Heroku 现在支持子模块。
http://devcenter.heroku.com/articles/git-submodules
但是,此功能不支持以下子模块:是私人的。
Heroku now supports submodules.
http://devcenter.heroku.com/articles/git-submodules
However, this feature does not support submodules that are private.
@Daniel Eisenhardt 方法还有另一种替代方法: https://stackoverflow.com/a/29464430/990356
转到 < a href="https://github.com/settings/tokens" rel="nofollow noreferrer">设置 >个人访问令牌并生成启用了
repo
范围的个人访问令牌。现在您可以执行
git clone https://[email protected]/user-or-org/repo
以及子模块的情况git 子模块添加 https://[电子邮件受保护]/user -or-org/repo
优点:
缺点:
There is another alternative to @Daniel Eisenhardt approach: https://stackoverflow.com/a/29464430/990356
Go to Settings > Personal access tokens and generate a personal access token with
repo
scope enabled.Now you can do
git clone https://[email protected]/user-or-org/repo
and in the case of a submodulegit submodule add https://[email protected]/user-or-org/repo
Pros:
Cons:
由于 Heroku 目前不支持子模块,另一种可能的方法是使用 sub-树合并。
基本上,子树合并是一种 Git 合并策略,允许您将另一个 git 存储库合并到您的存储库中,但在您选择的子目录中。有一个名为
git-subtree
的工具,它试图包装这个过程类似于 git-submodule(1) 的方式。除了
git-merge(1)
手册页之外,还有一些其他文章可以帮助您实现此合并策略:Since Heroku doesn't currently support submodules, one other possible way would be to use sub-tree merging.
Basically, sub-tree merging is a Git merging strategy that allows you to merge another git repository into yours, but in a subdirectory of your choosing. There's a tool called
git-subtree
, which tries to wrap this process in a way similar togit-submodule(1)
.Other than the
git-merge(1)
man page, there are a few other articles that can help you with this merging strategy:您只需添加公共子模块,heroku 就会在您部署时为您获取它们。
Heroku 在此处解释说,您可以将私有子模块添加到存储库中,但您需要包含可能存在安全问题的凭据:
不幸的是,当您执行此操作时,git 以纯文本形式存储您的用户名和密码。
You can simply add public submodules and heroku will fetch them for you when you deploy.
Heroku explains here that you can add private submodules to your repository, but you need to include the credentials which could be a security issue:
Unfortunately git stores your username and password in plain text when you do this.