ruby on rails - Heroku推送被拒绝,在重新安装操作系统后



我遵循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 repo:

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

当然,要为我的代码修改它将像这样:

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

但是我仍然不能从命令行推送,我一直在使用heroku部署按钮,让我部署主分支,但我认为这不是一个好主意,否则我认为它会在书中提到。任何帮助都将不胜感激。

如果有人想知道,我确实安装了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.

您需要执行git pull heroku master以在本地合并您的heroku更改。当你做一个git pull时,它做的是git pull origin master,也就是github,而不是heroku。所以,无论你对英雄库做了什么改变,都会引起冲突。

同样,你需要在命令行中使用

设置git匹配选项。
  • git config --global push.default matching

  • git config --global push.default simple .

告诉git要推送哪个分支,而不是需要显式地推送,比如主分支git push heroku master。这就是错误信息试图告诉你的。

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

这将在Hartl教程的1.4.1节中介绍,您需要执行以下操作:

$ 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

你应该指定你要推送给Heroku的分支。

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

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

git push heroku yourBranchName:master

也-错误信息是告诉你git pull再推之前。你应该这么做

我修复了它,并通过heroku的网站创建了一个新的heroku repo,然后添加了repo:

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的人发现这很困难,并且需要在将来参考它。你应该将whisper -hamlet-1487替换为你的应用程序的名称。

不幸的是,我找不到继续使用旧的repo的方法,但老实说,这并不重要,它看起来像一个完整的pta。最好还是放弃这件事。如果有人知道一种无需创建新仓库就能做到这一点的方法,我将非常欢迎,因为我认为在生产过程中这不是最好的行动方案。

最新更新