无法将一些引用推送到git@heroku.com

103
当我尝试推送到Heroku仓库时,出现了这个错误。
我已经在gitconfig中设置了autocrlf = false,但问题仍然存在。我也尝试过here的解决方案,但没有用。
是否有可能git仍在使用旧的配置设置?如果是,那么我该如何刷新它?
C:\myapp>git push heroku
To git@heroku.com:myapp.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@heroku.com:myapp.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

在尝试执行 git pull heroku master 命令时:
warning: no common commits
remote: Counting objects: 215, done.
remote: Compressing objects: 100% (147/147), done.
remote: Total 215 (delta 82), reused 132 (delta 62)Receiving objects:  79% (170/

Receiving objects: 100% (215/215), 1.49 MiB | 107 KiB/s, done.
Resolving deltas: 100% (82/82), done.
From heroku.com:myapp
 * branch            master     -> FETCH_HEAD
Auto-merging start.php
CONFLICT (add/add): Merge conflict in start.php
Auto-merging src/appinfo.txt
CONFLICT (add/add): Merge conflict in src/appinfo.txt
Auto-merging result.php
CONFLICT (add/add): Merge conflict in result.php
Auto-merging landhere.php
CONFLICT (add/add): Merge conflict in landhere.php
Automatic merge failed; fix conflicts and then commit the result.

在尝试执行git push heroku -f时:
F:\myapp>git remote add heroku git@heroku.com:myapp.git
F:\myapp>git push heroku

Counting objects: 41, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (40/40), done.
Writing objects: 100% (41/41), 1.36 MiB | 12 KiB/s, done.
Total 41 (delta 0), reused 0 (delta 0)

-----> Heroku receiving push
 !     Heroku push rejected, no Cedar-supported app detected

To git@heroku.com:myapp.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:myapp.git'
33个回答

86

试着使用

git push heroku main

取代

git push heroku master
原因:由于Git的默认起始分支已从master更改为main,因此您的Git命令无法识别master分支,并向您提供“ref”错误。

这个早期的答案链接到一篇文章,记录了从主分支更改为主要分支的变化:https://dev59.com/5Wkw5IYBdhLWcg3wlbd3#66737426 - Gino Mempin

72
在Heroku中,您可能会在推送到主分支时遇到问题。 我只需要使用以下命令开始一个新的分支:
git checkout -b masterbranch

然后使用推送

git push heroku masterbranch

请按照上述方式尝试!


构建不适用于您提到的方法。 - Saad Abbasi

66

这个错误意味着远程仓库已经提交了一些改动,如果你继续推送,这些改动将会被覆盖。首先执行 "git pull" 命令来进行合并,然后再次推送。


4
它在第一次运行时对我有帮助,但现在我又遇到了这个错误,即使是拉取也不能解决它,有没有一种方法可以清除所有内容,这样我就可以轻松地推送我的新内容而不会出现任何问题? - user971741
13
如果您是唯一使用该代码库的人,则可以执行git push -f命令,将当前提交推送到上游分支,而不考虑两者之间的关系。 - amcnabb
2
"(pre-receive hook declined)" 表示 pre-receive hook 没有接受您的提交。上面一行说“Heroku push rejected, no Cedar-supported app detected”清楚地说明了原因。我认为您应该尝试找到特定的问题,如果这不起作用,就发布另一个更具体的问题。您的跟进问题实际上是关于 Heroku 而不是 git。祝好运。 - amcnabb
8
我跟帖中描述的情况一样,git pull 对我没用。 - TaLha Khan
如果您的错误信息略有不同,您可以考虑创建一个新问题。 - amcnabb
显示剩余4条评论

22

18

我是唯一在开发我的应用程序的人,而且只从我的台式电脑上进行开发,所以我成功将 Heroku 存储库升级到 dev 以上的可能性并不合理。但是!最近,一个 Heroku 支持人员为了解决与 gem 安装相关的缓存问题查看了我的 Heroku 帐户,并更改了某些内容,导致 Heroku 返回与上述错误相同的错误。只需要执行 git pull heroku master 即可解决该问题。然后我找到了代表所做的微小更改,并自己恢复了它。


11

我曾经遇到过同样的问题。

解决方法是,在我的分支中,名为“testBranchSuper”,我使用了:

git checkout -b main

然后我使用了

git push heroku main

10

如果您想向Git仓库推送提交,请确保已将其他分支的所有提交合并。

合并后,如果无法推送提交,请使用带有-f的push命令:

git push -f origin branch-name

origin为你的远程仓库名称时。


1
Github已经从Master分支更改为main分支...因此在部署时,请使用 git push heroku main - Sawo Cliff

5

如果我不是唯一使用某人的“FULL STACK OVERMEGASUPER EASY AND COOL”Udemy课程的初学者,那么我写这篇文章(为了增加可能解决方案的列表)。我遇到了以下错误:

   remote: -----> Build
remote:        Running build
remote:        
remote:        > shop@1.0.0 build /tmp/build_cb8c8cb5
remote:        > cd frontend && npm install && npm run build
remote:
remote: sh: 1: cd: can't cd to frontend
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 2
remote: npm ERR! shop@1.0.0 build: `cd frontend && npm install && npm run build`
remote: npm ERR! Exit status 2
remote: npm ERR!
remote: npm ERR! Failed at the shop@1.0.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

remote: !       Push rejected to shop.
remote:
To https://git.heroku.com/shop.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/shop.git'

我尝试了其他用户提供的几乎所有方法,但是没有解决我的问题。最后,我变得足够好奇,查看了日志(出于某种原因,我一开始就转向了互联网)。
解决方案如下:
  1. 打开 package.json 文件并删除 "scripts" 中的 "build" 行;
  2. git add .
  3. git commit -your message-
  4. git push heroku main
这次,构建成功了。这是一个非常愚蠢的错误。终端告诉我出了什么问题,但我没有注意到它。

2
请解释一下什么出了问题,以及你的答案为什么有效。 - Kristian
1
是的,我也一样。请解释一下它是如何工作的。我也遇到了那个问题,但你的答案有效。 - vishal
@vishal 我猜这可能与“构建”脚本设置错误有关。在我的情况下,我想通过“cd”进入另一个目录作为构建脚本的第一步,但它无法实现。简而言之,请注意您在脚本中设置的指令。 - ArtemNovikov
@ArtemNovikov 我遇到了新的错误。Heroku日志 --tail. 错误代码h10、h12、h13。 - vishal
@vishal 我也遇到了这些问题。它们与 package.json 没有任何关系。 - ArtemNovikov

5

确保您正在推送正确的分支。我没有在master上,一直在想为什么会出错:P


4

对我而言,强制推送(force-pushing)起作用了。

git push heroku master --force

这种情况适用于当前分支中推送的提交被删除(该提交已经推送到远程仓库)。


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