重新安装 OS 后,Heroku 推送被拒绝了吗?

Heroku push is being rejected, after reinstallation of OS?

我正在学习 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 存储库:

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 工具带。

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

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。因此,您对 heroku 所做的任何更改都会导致冲突。

此外,您需要使用

从命令行设置 git 匹配选项
  • git config --global push.default matching

  • git config --global push.default simple.

那些告诉 git 要推送哪个分支而不是需要显式推送,例如主分支 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

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

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

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

git push heroku yourBranchName:master

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

我修复了它,通过 heroku 的站点创建了一个新的 heroku 存储库,然后添加了存储库:

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

不幸的是,这导致在一个目录中有 "multiple" 个 heroku 应用程序,因此要迁移数据库,就像我们在 Micheal Hartl 的书中清单 7.30 中应该做的那样,它不能再使用这个迁移:

heroku run rake db:migrate

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

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

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

不幸的是,我找不到继续使用旧存储库的方法,但老实说这并不重要,它似乎完全是 pta。放弃这个要好得多。如果有人知道无需创建新回购协议即可执行此操作的方法,我将非常欢迎,因为我认为在生产过程中这不是最佳做法。