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

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

问题描述

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

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

虽然我确定Heroku的设计师对此政策有充分的理由(我想是为了进行存储和性能优化),但对我来说,作为开发人员的结果是,无论我在从事什么本地主题分支工作,我都想将Heroku的master切换到该本地主题分支并执行"git push heroku -f"以覆盖Heroku上的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.

通过阅读 http://progit.org/book/ch9-5.html

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

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

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!

当然,需要注意的是,只有当我是唯一可以推送到该Heroku应用程序/存储库的人时,这才有意义.测试或质量检查团队可能会管理这样的存储库以尝试不同的候选分支,但是他们必须进行协调,以便他们在任何一天都同意将其推向哪个分支.

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.

不用说,拥有一个独立的远程存储库(如GitHub)而不用限制所有内容的备份也是一个很好的主意.我会称其为起源",并为Heroku使用"heroku",以便"git push"始终将所有内容备份到原始位置,而"git push heroku"会将我当前所在的任何分支推入Heroku的master分支,并覆盖它如有必要.

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.

这项工作可以吗?


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

尽管我想我可以在Heroku上创建一个虚拟应用程序并对此进行试验,但我还是想听听经验更丰富的人的信.

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.

关于获取,我并不在乎Heroku存储库是否仅写.我仍然有一个单独的存储库,例如GitHub,用于备份和克隆我的所有工作.

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?

推荐答案

使用通配符时,它必须出现在refspec的两侧,因此 + refs/heads/*:refs/heads/master不起作用.但是您可以使用 + HEAD:refs/heads/master :

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

此外,您可以直接通过 git push 进行此操作:

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天全站免登陆