如何将本地不同的 Git 分支推送到 Heroku/master
Heroku 的政策是忽略除“master”之外的所有分支。
虽然我确信 Heroku 的设计者对这个政策有很好的理由(我猜测是为了存储和性能优化),但对我作为开发人员来说,结果是无论我正在研究什么本地主题分支,我都想要一种简单的方法将 Heroku 的 master 切换到本地主题分支,并执行“git push heroku -f”来覆盖 Heroku 上的 master。
我从阅读 http://progit.org/book/ch9 的“Pushing Refspecs”部分得到了什么-5.html 是
git push -f heroku local-topic-branch:refs/heads/master
我真正想要的一种在配置文件中进行设置的方法,以便“git push heroku”始终执行上述操作,替换 local-topic-branch 与我当前分支的名称相同。如果有人知道如何实现这一点,请告诉我!
当然,需要注意的是,只有当我是唯一可以推送到该 Heroku 应用程序/存储库的人时,这才是明智的。测试或 QA 团队可能会管理这样的存储库来尝试不同的候选分支,但他们必须进行协调,以便他们都同意在任何一天推送到哪个分支。
不用说,拥有一个单独的远程存储库(如 GitHub)并且没有此限制来备份所有内容也是一个非常好的主意。我将其称为“origin”,并为 Heroku 使用“heroku”,以便“git Push”始终将所有内容备份到 origin,而“git Push heroku”则将我当前所在的任何分支推送到 Heroku 的 master 分支,并覆盖它如果需要的话。
这行得通吗?
[remote "heroku"] url = [email protected]:my-app.git push = +refs/heads/*:refs/heads/master
在开始实验之前,我想听听更有经验的人的意见,尽管我想我可以在 Heroku 上创建一个虚拟应用程序并进行实验。
至于获取,我并不关心 Heroku 存储库是否是只写的。我仍然有一个单独的存储库,例如 GitHub,用于备份和克隆我的所有工作。
脚注:这个问题类似于,但不完全相同 使用 Heroku 的分支策略进行良好的 Git 部署?
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 = [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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
请参阅https://devcenter.heroku.com/articles/git#deploying-code
See https://devcenter.heroku.com/articles/git#deploying-code
使用通配符时,它必须出现在 refspec 的两侧,因此
+refs/heads/*:refs/heads/master
将不起作用。但您可以使用 +HEAD:refs/heads/master :此外,您可以直接使用 git push 来执行此操作:
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
:Also, you can do this directly with git push:
对我来说,它有效,
来源:- 官方文档
For me, it works,
source :- offical docs
将不同本地 Git 分支推送到 Heroku/master 的最安全命令。
注意:虽然您可以在不使用 -f 的情况下进行推送,但建议使用 -f(强制标志)以避免与其他开发人员的推送发生冲突。
The safest command to push different local Git branches to Heroku/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.
另请注意,如果您使用 git flow 系统并且可能会调用您的功能分支,
并且使用名为 stagingtwo 的 git 远程,那么推送到 heroku 的命令将是
Also note that if your using the git flow system and your feature branch might be called
and with a git remote called stagingtwo, then the command to push to heroku would be
交替:
Alternately:
你应该看看heroku_san,它很好地解决了这个问题。
例如,您可以:
它还可以轻松启动新的 Heroku 实例以将主题分支部署到新服务器:
当然,如果您经常执行某些操作,您可以执行更简单的 rake 任务。
You should check out heroku_san, it solves this problem quite nicely.
For example, you could:
It also makes it easy to spin up new Heroku instances to deploy a topic branch to new servers:
And of course you can make simpler rake tasks if you do something frequently.
我发现这很有帮助。
http://jqr.github.com/ 2009/04/25/deploying-multiple-environments-on-heroku.html
I found this helpful.
http://jqr.github.com/2009/04/25/deploying-multiple-environments-on-heroku.html
Heroku 实验室现在提供了一个 github 插件,可让您指定要推送的分支。
查看 Heroku 关于此测试版功能的文章。
您需要注册为暂时是 beta 测试员。
Heroku labs now offers a github add-on that let's you specify which branch to push.
See Heroku's write up on this beta feature.
You'll need to sign-up as a beta tester for the time-being.
在 2022 年的某个时候,语法“git push heroku otherbranchname:master”不再对我有用。它总是只返回“一切都是最新的”。查阅 Heroku 文档后,我发现“master”已更改为“main”,因此语法现在是这样的:
git push heroku otherbranchname:main
At some point in 2022, the syntax 'git push heroku otherbranchname:master' stopped working for me. It would always just return "Everything up-to-date". After consulting the Heroku docs, I found that "master" had been changed to "main", so the syntax is now like this:
git push heroku otherbranchname:main
我认为应该是
push = refs/heads/*:refs/heads/*
...
I think it should be
push = refs/heads/*:refs/heads/*
instead...