GitHub 到 Heroku 提交错误

3

我正在使用Aptana Studio 3和Heroku进行一个RoR网站项目。当我通过GitHub提交后将网站推送到Heroku时,我一直收到以下错误。我已经搜索了所有地方,但找不到可以遵循的简单解决方案。有什么建议是出了什么问题以及如何解决?谢谢。

User$ git push heroku master
To git@heroku.com:xxxxxx.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@heroku.com:xxxxxx.git'
To prevent you from losing history, non-fast-forward updates were rejected.
Merge the remote changes before pushing again.
See 'non-fast forward' section of 'git push --help' for details.
User$ 

我按照@SkillDrick的以下建议尝试了一下,得到了这个结果,但最后出现了错误:

User$ git merge heroku/master master
usage: git merge [options] <remote>...
or: git merge [options] <msg> HEAD <remote>

-n                    do not show a diffstat at the end of the merge
--stat                show a diffstat at the end of the merge
--summary             (synonym to --stat)
--log                 add list of one-line log to merge commit message
--squash              create a single commit instead of doing a merge
--commit              perform a commit if the merge succeeds (default)
--ff                  allow fast forward (default)
-s, --strategy <strategy>
                      merge strategy to use
-m, --message <message>
                      message to be used for the merge commit (if any)
-v, --verbose         be more verbose
-q, --quiet           be more quiet



user$ git push heroku master
To git@heroku.com:worrybin.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@heroku.com:worrybin.git'
To prevent you from losing history, non-fast-forward updates were rejected.
Merge the remote changes before pushing again.
See 'non-fast forward' section of 'git push --help' for details.

1
当你执行了 git merge heroku/master master(我的错误)并且它显示了 usage 等信息时,那是在告诉你命令不正确,因此它实际上没有合并。 - Skilldrick
4个回答

6
我遇到了同样的问题。一个非常简单的解决方案是强制推送:
git push heroku master -f
由于 Heroku 只用于部署您的应用程序(而不是像 origin/master 那样用于源代码控制),这应该没问题。

5

由于某种原因,您的Heroku代码库发生了分歧。您可以执行以下操作:

git fetch heroku
git merge heroku/master
git push heroku master

在重新推送之前合并远程更改。在合并之前,可以使用 git diff heroku/master 查看实际的差异。


谢谢建议。我尝试了,但仍然遇到相同的错误 - 我已经在上面发布了详细信息。 - ubique
@ubique 抱歉,我写错了。第二个命令应该只是 git merge heroku/master - Skilldrick
现在收到这个消息...有什么想法吗?user$ git merge heroku/master 错误:未跟踪的工作树文件“._.DS_Store”将被合并覆盖。 致命错误:树5a008289e74cc3eb95880b1cf51b532c6aed66b2和6073db0f540dc1960070d996fd93484aab73439b的合并失败。 - ubique

0

执行 git pull 然后执行 git push


1
git pull 返回 'already up to date',而 git push 返回 'everything up to date'。有什么想法吗? - ubique

0

像manojlds所说,先执行git pull。

实际上,在做任何事之前,请检查您的本地repo是否有更改。

git status

如果没有冲突,执行git pull heroku master。如果有更改,请提交或隐藏它们。(我建议现在只是隐藏)

在你拉取代码之后(希望没有任何冲突),执行git push heroku master,然后你就可以了。如果有冲突,请先解决它们,再提交,然后推送。

基本上发生的情况是你的heroku仓库与当前仓库不同步。这通常发生在以下场景中:

  1. 用户A进行更改,将其推送到heroku和github仓库。
  2. 用户B拉取代码,进行更改,将其推送到heroku仓库,但忘记推送到github仓库。
  3. 用户A从github仓库拉取代码并尝试将其推送到heroku仓库。

在这种情况下,你是用户A,这意味着你拉取了一些不在heroku仓库中的代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接