Heroku:如何将不同的本地 Git 分支推送到 Heroku/master [英] Heroku: How to push different local Git branches to Heroku/master

查看:22
本文介绍了Heroku:如何将不同的本地 Git 分支推送到 Heroku/master的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heroku 的策略是忽略除master"之外的所有分支.

虽然我确信 Heroku 的设计者有很好的理由支持这个政策(我猜测是为了存储和性能优化),但对我作为开发人员的结果是,无论我在做什么本地主题分支,我都希望一种将 Heroku 的 master 切换到该本地主题分支并执行git push heroku -f"以覆盖 Heroku 上的 master 的简单方法.

我从http://progit.org/的推送参考规范"部分中得到了什么book/ch9-5.html

git push -f heroku local-topic-branch:refs/heads/master

我真正想要的是一种在配置文件中进行设置的方法,以便git push heroku"始终执行上述操作,将 local-topic-branch 替换为任何名称我目前的分支恰好是.如果有人知道如何做到这一点,请告诉我!

当然,对此的警告是,只有当我是唯一可以推送到该 Heroku 应用程序/存储库的人时,这才是明智的.测试或 QA 团队可能会管理这样一个存储库来尝试不同的候选分支,但他们必须进行协调,以便他们就在任何一天推送到哪个分支达成一致.

不用说,拥有一个单独的远程存储库(如 GitHub)而没有此限制来备份所有内容也是一个非常好的主意.我将其称为原点"并为 Heroku 使用heroku",以便git push"始终将所有内容备份到原点,而git push heroku"将我当前所在的任何分支推送到 Heroku 的主分支,覆盖它如有必要.

这行得通吗?

<前>[远程heroku"]url = git@heroku.com:my-app.gitpush = +refs/heads/*:refs/heads/master

在我开始实验之前,我想听听更有经验的人的意见,尽管我想我可以在 Heroku 上创建一个虚拟应用程序并进行实验.

至于获取,我真的不在乎 Heroku 存储库是否是只写的.我还有一个单独的存储库,比如 GitHub,用于备份和克隆我所有的工作.

脚注:这个问题与在 Heroku 中使用分支策略进行良好的 Git 部署?

解决方案

当使用通配符时,它必须出现在 refspec 的两边,所以 +refs/heads/*:refs/heads/master 将不起作用.但是你可以使用 +HEAD:refs/heads/master:

git config remote.heroku.push +HEAD:refs/heads/master

此外,您可以直接使用 git push 执行此操作:

git push heroku +HEAD:mastergit push -f heroku HEAD:master

Heroku has a policy of ignoring all branches but 'master'.

While I'm sure Heroku's designers have excellent reasons for this policy (I'm guessing for storage and performance optimization), the consequence to me as a developer is that whatever local topic branch I may be working on, I would like an easy way to switch Heroku's master to that local topic branch and do a "git push heroku -f" to over-write master on Heroku.

What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.html is

git push -f heroku local-topic-branch:refs/heads/master

What I'd really like is a way to set this up in the configuration file so that "git push heroku" always does the above, replacing local-topic-branch with the name of whatever my current branch happens to be. If anyone knows how to accomplish that, please let me know!

The caveat for this, of course, is that this is only sensible if I am the only one who can push to that Heroku app/repository. A test or QA team might manage such a repository to try out different candidate branches, but they would have to coordinate so that they all agree on what branch they are pushing to it on any given day.

Needless to say, it would also be a very good idea to have a separate remote repository (like GitHub) without this restriction for backing everything up to. I'd call that one "origin" and use "heroku" for Heroku so that "git push" always backs up everything to origin, and "git push heroku" pushes whatever branch I'm currently on to Heroku's master branch, overwriting it if necessary.

Would this work?

[remote "heroku"]
    url = git@heroku.com:my-app.git
    push = +refs/heads/*:refs/heads/master

I'd like to hear from someone more experienced before I begin to experiment, although I suppose I could create a dummy app on Heroku and experiment with that.

As for fetching, I don't really care if the Heroku repository is write-only. I still have a separate repository, like GitHub, for backup and cloning of all my work.

Footnote: This question is similar to, but not quite the same as Good Git deployment using branches strategy with Heroku?

解决方案

When using a wildcard, it had to be present on both sides of the refspec, so +refs/heads/*:refs/heads/master will not work. But you can use +HEAD:refs/heads/master:

git config remote.heroku.push +HEAD:refs/heads/master

Also, you can do this directly with git push:

git push heroku +HEAD:master
git push -f heroku HEAD:master

这篇关于Heroku:如何将不同的本地 Git 分支推送到 Heroku/master的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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