场景如下:
1) 我和我的项目合作伙伴正在使用 github 作为我们的代码库一起开发 Ruby on Rails 应用程序。
2) 该应用程序在她的github帐户下,她已将我添加为合作者
3) 她部署到 Heroku 并将我也添加为协作者
4) 我从我现有的应用程序目录中使用了以下命令,目的是将现有的 Heroku 远程应用程序作为远程添加到我现有的本地应用程序。正如我之前提到的,我现有的本地应用程序已经有一个远程 github
git remote add heroku git@heroku.com:codefellow.git
5) 我做了一些更改并将它们推送到 github,所有都是最新的
6) 然后我尝试使用以下命令推送到 heroku
git push heroku master
7) 这给了我一个错误,说我的分支的尖端落后了,如下所示,但是当我试图从 github 中 pull 时,它说我是最新的,如下所示
➜ code-fellows-alumni git:(master) git push heroku master
To git@heroku.com:codefellow.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:codefellow.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
➜ code-fellows-alumni git:(master) git pull
Already up-to-date.
所以有人知道这里发生了什么吗?如果我与 Github 保持同步,我的本地分支怎么会与 Heroku 不同步?我的项目合作伙伴是否可以在不先将更改推送到 Github 的情况下将更改推送到 Heroku?我检查了一下,她没有应用程序的分支。我现在无法与她取得联系,无法确定她可能做了什么——我什至不确定如果这些更改还没有被推送到 Github,她是否可以将更改推送到 Heroku。任何见解将不胜感激。我不想从 Heroku 克隆应用程序,因为我已经在本地与 Github 同步了它。我想使用 Github 作为代码存储库,我不愿意从 Heroku 的克隆开始。我已经看过关于这个的 Heroku 文档:https://devcenter.heroku.com/articles/git .它只是说要做一个克隆,但出于上述原因我不想这样做。我按照这个问题 (How to link a folder with an existing Heroku app) 的答案中给出的指示进行了这一步,但似乎缺少了一 block ,否则我的项目合作伙伴做了一些不寻常的事情。预先感谢您提供任何有用的想法。
最佳答案
您看到的消息表示已对本地副本中没有的应用程序进行了更改。当你推送时它被拒绝了,因为 Heroku 远程比你的远程更远,所以你认为你的合作伙伴已经推送到 Heroku 而没有推送到 Github 是正确的 - 这是一种常见的情况,因为当你部署到 Heroku 时你从本地存储库部署,不像传统的 Capistrano 部署,后者通常会从 Github 部署代码。
这取决于您作为一个团队想出防止这种情况发生的工作方式,但如果您需要立即开始工作,您可以选择
git push heroku master -f
。这会强制您进行更改,并将覆盖您的代码中目前存在的内容git pull heroku master
将更改从 Heroku pull 入您的本地存储库,然后当您有更改时,您应该可以执行git push heroku master
。<
关于ruby-on-rails - 将远程 heroku 存储库添加到我现有的本地存储库后无法推送到 heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18669963/