【问题标题】:Heroku push is being rejected, after reinstallation of OS?安装操作系统后 Heroku 推送被拒绝?
【发布时间】:2015-05-19 09:32:31
【问题描述】:

我正在学习 Michael Hartl 制作的教程,但我倾向于在 Linux 上进行很多发行版。我从 github 克隆了我的 repo,我做得很好。但是我不能再推送到heroku,我不确定为什么……

这是我要运行的命令:

$ bundle exec rake test
$ git add -A
$ git commit -m "Use SSL and the Puma webserver in production"
$ git push
$ git push heroku
$ heroku run rake db:migrate

在最后一部分之前一切正常:

git push heroku
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

In Git 2.0, Git will default to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

To git@heroku.com:morning-stream-6357.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:morning-stream-6357.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我完全不确定如何解决这个问题:/ 有人可以帮忙吗?我对此进行了研究,并使用以下方法添加了远程 heroku 存储库:

git remote add heroku-remote git@heroku.com:project.git

当然要为我的代码修改它是这样的:

git remote add heroku-remote git@heroku.com:morning-stream-6357.git

但是我仍然无法从命令行推送,我一直在使用 heroku 部署按钮进行推送,该按钮可以让我部署 master 分支,但我认为这不是一个好主意,否则我认为会在这本书。任何帮助都将不胜感激。

编辑:如果有人想知道,我确实安装了 heroku 工具带。

编辑:我之前应该注意到我确实已经尝试过运行这个命令:

git push heroku master

但它仍然给我一个错误:

jose@jose-desktop:~/Workspace/sample_app$ git push heroku master
To git@heroku.com:morning-stream-6357.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:morning-stream-6357.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我不确定是什么原因造成的,它应该是最新的。我克隆了 repo,之前我已经从 heroku 的 github 连接手动部署,所以它应该是最新的。

git pull

结果如下:

jose@jose-desktop:~/Workspace/sample_app$ git pull
Already up-to-date.

【问题讨论】:

  • 你拉的像它说的那样吗?
  • hint: 'git pull ...') 在再次推送之前。

标签: ruby-on-rails git heroku github heroku-toolbelt


【解决方案1】:

您需要通过git pull heroku master在本地合并您的heroku 更改。当您执行git pull 时,它正在执行git pull origin master,这是github 而不是heroku。因此,您向 heroku 推送的任何更改都会导致冲突。

另外,您需要使用命令行设置 git 匹配选项

  • git config --global push.default matching

  • git config --global push.default simple

那些告诉 git 推送哪个分支而不是需要显式推送,例如使用 master 分支 git push heroku master。这就是该错误消息试图告诉您的内容。

注意:Heroku 只会接受你的 master 分支,除非你明确告诉它 git push heroku yourbranch:masterhttps://devcenter.heroku.com/articles/git

这在 Hartl 教程中的 1.4.1 Installation and setup 部分中进行了介绍,您需要执行以下操作:

$ git config --global user.name "Your Name"
$ git config --global user.email your.email@example.com
$ git config --global push.default matching
$ git config --global alias.co checkout

【讨论】:

    【解决方案2】:

    您应该指定要推送到 Heroku 的分支。

    尝试运行git push heroku master 而不是git push Heroku

    如果你想将 master 以外的分支推送到 Heroku,那么你可以这样做:

    git push heroku yourBranchName:master
    

    另外 - 错误消息告诉您在再次推送之前git pull。你应该这样做。

    【讨论】:

      【解决方案3】:

      我只是用它来修复它,并通过 heroku 的网站创建一个新的 heroku 存储库,然后添加该存储库:

      heroku login
      heroku git:clone -a whispering-hamlet-1487
      

      不幸的是,这导致在一个目录中存在“多个”heroku 应用程序,因此要迁移数据库,正如我们在 Micheal Hartl 的书中清单 7.30 中所设想的那样,它不能再使用以下方法迁移:

      heroku run rake db:migrate
      

      相反,它必须使用以下方式迁移:

      heroku run rake db:migrate -app whispering-hamlet-1487
      

      我把它完整地写了出来,以防其他学习 Rails 的人觉得这很困难,并且需要在将来参考它。你应该用你的应用程序的名字来替换whispering-hamlet-1487。

      不幸的是,我找不到继续使用旧存储库的方法,但老实说,这并不重要,这似乎是一个完整的 pta。放弃这一点要好得多。如果有人知道无需创建新存储库就可以做到这一点,我会非常欢迎,因为我认为在生产过程中这不是最好的做法。

      【讨论】:

      • 你在旧的 repo 上尝试过 git pull heroku master 吗?
      • 你能给我解释一下吗?当我想在另一台机器上处理我的代码时,我应该从 github 拉取还是从 heroku 拉取,我真的不明白为什么我不应该只从 github 拉取并完成它这个过程是如何工作的?
      猜你喜欢
      • 2017-01-09
      • 2021-09-22
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2011-06-02
      相关资源
      最近更新 更多