如何将不同的本地 Git 分支推送到 Heroku/master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2971550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to push different local Git branches to Heroku/master
提问by Lawrence I. Siden
Heroku has a policy of ignoring all branches but 'master'.
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.
虽然我确信 Heroku 的设计者对这个政策有很好的理由(我猜是为了存储和性能优化),但对我作为开发人员的结果是,无论我可能在做什么本地主题分支,我都想要一个简单的方法将 Heroku 的 master 切换到该本地主题分支并执行“git push heroku -f”以覆盖 Heroku 上的 master。
What I got from reading the "Pushing Refspecs" section of http://progit.org/book/ch9-5.htmlis
我从阅读http://progit.org/book/ch9-5.html的“Pushing Refspecs”部分中得到的是
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-branchwith the name of whatever my current branch happens to be. If anyone knows how to accomplish that, please let me know!
我真正想要的是一种在配置文件中进行设置的方法,以便“git push heroku”始终执行上述操作,将local-topic-branch替换为我当前分支的名称。如果有人知道如何做到这一点,请告诉我!
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.
当然,对此的警告是,只有当我是唯一可以推送到该 Heroku 应用程序/存储库的人时,这才是明智的。测试或 QA 团队可能会管理这样的存储库以尝试不同的候选分支,但他们必须进行协调,以便他们都同意在任何一天推送到哪个分支。
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.
毋庸置疑,拥有一个单独的远程存储库(如 GitHub)而不受此限制来备份所有内容也是一个非常好的主意。我将其称为“起源”并为 Heroku 使用“heroku”,以便“git push”始终将所有内容备份到起源,而“git push heroku”将我当前所在的任何分支推送到 Heroku 的主分支,覆盖它如有必要。
Would this work?
这行得通吗?
[remote "heroku"] url = [email protected]: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.
在我开始实验之前,我想听听更有经验的人的意见,尽管我想我可以在 Heroku 上创建一个虚拟应用程序并进行实验。
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.
至于获取,我真的不在乎 Heroku 存储库是否是只写的。我还有一个单独的存储库,比如 GitHub,用于备份和克隆我所有的工作。
Footnote: This question is similar to, but not quite the same as Good Git deployment using branches strategy with Heroku?
脚注:这个问题与使用 Heroku 分支策略的 Good Git 部署类似,但不完全相同?
采纳答案by Chris Johnsen
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
:
使用通配符时,它必须出现在 refspec 的两侧,因此+refs/heads/*:refs/heads/master
不起作用。但你可以使用+HEAD:refs/heads/master
:
git config remote.heroku.push +HEAD:refs/heads/master
Also, you can do this directly with git push:
此外,您可以直接使用git push执行此操作:
git push heroku +HEAD:master
git push -f heroku HEAD:master
回答by jassa
See https://devcenter.heroku.com/articles/git#deploying-code
见https://devcenter.heroku.com/articles/git#deploying-code
$ git push heroku yourbranch:master
回答by Tomasz Mazur
git push -f heroku local_branch_name:master
回答by techdreams
The safest command to push different local Git branches to Heroku/master.
将不同的本地 Git 分支推送到 Heroku/master 的最安全命令。
git push -f heroku branch_name:master
Note:Although, you can push without using the -f, the -f (force flag) is recommended in order to avoid conflicts with other developers' pushes.
注意:虽然您可以不使用 -f 进行推送,但建议使用 -f(强制标志)以避免与其他开发人员的推送发生冲突。
回答by Ashad Nasim
For me, it works,
对我来说,它有效,
git push -f heroku otherBranch:master
The -f (force flag) is recommended in order to avoid conflicts with other developers' pushes. Since you are not using Git for your revision control, but as a transport only, using the force flag is a reasonable practice.
建议使用 -f(强制标志)以避免与其他开发人员的推送发生冲突。由于您没有将 Git 用于版本控制,而仅用作传输,因此使用 force 标志是一种合理的做法。
source :- offical docs
来源:-官方文档
回答by Jonathon Batson
Also note that if your using the git flow system and your feature branch might be called
另请注意,如果您使用 git flow 系统并且您的功能分支可能会被调用
feature/mobile_additions
and with a git remote called stagingtwo, then the command to push to heroku would be
并使用名为 stagingtwo 的 git remote,然后推送到 heroku 的命令将是
git push stagingtwo feature/mobile_additions:master
回答by jqr
You should check out heroku_san, it solves this problem quite nicely.
你应该看看heroku_san,它很好地解决了这个问题。
For example, you could:
例如,您可以:
git checkout BRANCH
rake qa deploy
It also makes it easy to spin up new Heroku instances to deploy a topic branch to new servers:
它还可以轻松启动新的 Heroku 实例以将主题分支部署到新服务器:
git checkout BRANCH
# edit config/heroku.yml with new app instance and shortname
rake shortname heroku:create deploy # auto creates deploys and migrates
And of course you can make simpler rake tasks if you do something frequently.
当然,如果你经常做一些事情,你可以做更简单的耙任务。
回答by David
回答by irth
Heroku labs now offers a github add-on that let's you specify which branch to push.
Heroku 实验室现在提供了一个 github 附加组件,让您可以指定要推送的分支。
See Heroku's write up on this beta feature.
You'll need to sign-up as a beta tester for the time-being.
您需要暂时注册为 Beta 版测试员。
回答by ken
I think it should be
我认为应该是
push = refs/heads/*:refs/heads/*
push = refs/heads/*:refs/heads/*
instead...
反而...