重新安装操作系统后,Heroku推送被拒绝了吗?

时间:2015-05-18 23:47:41

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

我遵循Michael Hartl的教程,但我倾向于在Linux上发布很多内容。我从github克隆了我的回购,我做得很好。但是我不能再推到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.

3 个答案:

答案 0 :(得分: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要推送哪个分支而不是需要显式推送,例如使用主分支git push heroku master。这就是该错误消息试图告诉您的内容。

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

在[{3}}部分的Hartl教程中介绍了这一点,您需要做一次:

$ 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

答案 1 :(得分:0)

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

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

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

git push heroku yourBranchName:master

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

答案 2 :(得分:-1)

我用它来修复它并通过heroku网站创建一个新的heroku repo然后添加回购:

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

不幸的是,这导致了"多个" heroku应用程序在一个目录中,所以为了迁移数据库,就像我们在清单7.30中在Micheal Hartl的书中所说的那样,它无法再使用它来迁移:

heroku run rake db:migrate

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

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

我完全写出来,以防其他人学习rails发现这很困难,并且需要在将来引用它。您应该将whispering-hamlet-1487替换为您的应用程序名称。

不幸的是,我无法找到继续使用旧回购的方法,但说实话,它并不重要,看起来像是一个完整的pta。放弃这个就好了好多了。如果有人知道如何在不创建新回购的情况下做到这一点,我非常欢迎,因为我认为在生产过程中这不是最好的行动方案。