代码推送到 heroku 不起作用 [英] code push to heroku not working
问题描述
我想在 gihub 上的 heroku 上推送代码
I want to push code on heroku that is on gihub
我使用了以下命令
git push heroku mybranch:master
错误是
To https://github.com/user/lyricle-new.git
! [rejected] lyricle-frt-backend -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/user/app.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
使用提示中提到的命令 git pull
响应是已经是最新的.
Used the command git pull
as mentioned in hint the response was Already up-to-date.
此错误背后的原因可能是什么?这是推动heroku的正确方法
What could be the reasons behind this error? and is this the correct way to push on heroku
推荐答案
通过执行 git push heroku mybranch:master
,你是在告诉 git 把你的 local mybranch
分支并将其与 remote master
分支(远程存储在您的 heroku 存储库中)合并.
你会得到一个错误,因为 master
在提交方面领先于 mybranch
.
By doing git push heroku mybranch:master
, you are telling git to take your local mybranch
branch and merge it with the remote master
branch (remotely stored on your heroku repo).
You get an error because master
is ahead of mybranch
in terms of commits.
考虑这个例子:master: --------b---------m---------
mybranch:........-c--c--/...........
在某个时候,您将 (b) master 分支到 mybranch,向分支提交 (c) 一些代码,然后合并 (m>) 它回到主人.
At some point, you branch (b) master into mybranch, commit (c) some code to the branch, and merge (m) it back to master.
现在考虑这个例子:master: --c-----b---c-----m---c---
mybranch:........-c--c---/.......
这几乎是相同的场景,但是当您向 mybranch
提交代码时,有人通过提交其他代码更新了 master
.如果你将 mybranch
合并回 master
,你可能会导致你的代码和包含在 master
中的新代码之间发生冲突,因此 Git 拒绝进行合并.首先,您必须使用新版本的 master
更新您的本地分支,然后只有 Git 允许您推送.
It is pretty much the same scenario but while you were committing code to mybranch
, someone updated master
by committing some other code. If you were to merge back mybranch
into master
, you would risk causing conflicts between your code and the new code contained in master
, thus Git refuses to do the merge. First, you have to update your local branch with the new version of master
and then only Git will allow you to push.
简而言之:
- git pull heroku master:mybranch
- 解决潜在的冲突
- 提交修改过的文件
- git push heroku mybranch:master
现在关于 Heroku,你应该总是像这样推送代码:git push heroku master
(考虑到你在本地的 master
分支上).你应该做的是避免像 git push heroku mybranch:master
这样的事情,当你完成一个分支的工作时,总是将你的更改合并到 master
然后(在验证之后一切正常)将 master 推送到 heroku.
Now about Heroku, you are supposed to always push code like this: git push heroku master
(considering you are on the master
branch locally). What you should do to avoid things like git push heroku mybranch:master
is, when you finish working on a branch, always merge your changes to master
and then (after verifying that everything is working) push master to heroku.
请参阅此资源以了解您正在寻找的简单 git 工作流程:https://www.atlassian.com/git/workflows#!workflow-feature-branch
See this resource for a simple git workflow that seem to be what you are looking for: https://www.atlassian.com/git/workflows#!workflow-feature-branch
一切最终都集中在 master 中,然后您可以定期将 master 推送到 heroku(理想情况下,您将为应用的每个版本推送一次)
Everything is centralized in master eventually, and you can then regularly push master to heroku (ideally you would push once for every version of your app)
这篇关于代码推送到 heroku 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!