【问题标题】:git, Heroku: pre-receive hook declinedgit,Heroku:预接收挂钩被拒绝
【发布时间】:2012-01-03 05:36:36
【问题描述】:

我正在建立一个 git 存储库并尝试将其链接到 Heroku。当我运行命令时

git push heroku master

我收到了

Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 714 bytes, done.
Total 7 (delta 1), reused 0 (delta 0)

-----> Heroku receiving push

 !     Heroku push rejected due to an unrecognized error.
 !     We've been notified, see http://support.heroku.com if the problem persists.


To git@heroku.com:morning-stream-3712.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:morning-stream-3712.git'

我不太确定还有哪些其他信息会有所帮助,以及哪些信息会弄得一团糟,所以我现在就暂且不谈。将我的应用程序推送到 Heroku 的任何帮助将不胜感激。谢谢。

【问题讨论】:

标签: ruby git heroku rack


【解决方案1】:

确保您推送包含适当支持的应用程序(Rails、Django 等)的存储库,而不仅仅是推送一些随机存储库来测试它。

Newbie in Heroku: Error when push my app to Heroku

如果情况并非如此,并且您正在推送您认为有效的应用程序,请联系 Heroku 支持,他们会为您解决问题。

【讨论】:

  • 你明白了,这就是问题所在。 “你好,拉克!”访问morning-stream-3712.heroku.com时成功打印到屏幕上:)
  • 谢谢!需要“package.json”,以便 heroku 知道它是一个节点应用程序。
  • 对我来说,我必须这样做:Heroku 登录 cmd,然后我看到了真正的错误 - 我有太多的 heroku 遥控器。花了5天时间——真的。欢迎您
【解决方案2】:

确保您使用的是 npm 或 yarn.lock 文件-

找到两个不同的锁文件:package-lock.json 和 yarn.lock npm 和 yarn 都为这个应用程序创建了锁文件, 但是只能使用一个来安装依赖。

删除 yarn.lock 并再次将代码推送到 git 后,我​​的问题解决了。

【讨论】:

  • 我遇到了同样的问题,删除 package-lock.json 并再次推送代码以解决我的问题,谢谢。
【解决方案3】:

删除 package-lock.json 为我解决了这个问题

【讨论】:

  • 对我来说,这是将 package-lock.json 添加到我的提交中
【解决方案4】:

我遇到了同样的问题:

! [remote rejected] vX.X.XX -> master (pre-receive hook declined) 
error: failed to push some refs to 'git@heroku.com:[application-name]'

我意识到我的 heroku 应用程序 Stack 是“cedar-10”,并于 2014 年 4 月 11 日被弃用,并于 2015 年 4 月 11 日被禁用 (Cedar-14 is now Generally Available)。

解决方案是按照指南升级 heroku 应用程序堆栈:

Upgrading the production app to Cedar-14

【讨论】:

    【解决方案5】:

    另一个问题可能是在生产环境中,您不能使用 sqlite3,这是您制作 rails 应用程序时的默认数据库。

    要解决此问题,只需将您的 rails 应用程序使用的数据库更改为 Postgres。这可以通过编辑您的 Gemfile

    轻松完成

    从您的 Gemfile 中删除:

    gem sqlite3;
    

    并添加以下内容:

    group :development, :test do
      gem 'sqlite3'
    end
    
    group :production do
      gem 'pg'
    end
    

    【讨论】:

    • 您应该始终为本地和生产环境使用相同的数据库类型。否则你不能确定,如果某些数据库特定的东西是一个问题
    【解决方案6】:

    首先,禁用collectstatic:

    heroku config:set DISABLE_COLLECTSTATIC=1
    

    然后运行:

    git push heroku master
    

    更多详情和完整步骤,check here

    【讨论】:

      【解决方案7】:

      我遇到了同样的问题,但是使用 Django 应用程序时,发现 pip 无法下载/安装 requirements.txt 文件的依赖项之一(它是 eyeD3)

      【讨论】:

        【解决方案8】:

        游戏有点晚了,我的一个问题是我有一个过时的 sshkey。只需在设置中更新即可。

        另一件事是我正在推动 Python Django CMS,它在部署期间运行 python manage.py collectstatic 并且失败了。所以一定要检查日志heroku logs --tail。这给了我另一个关闭 collectstatic 的提示,它会告诉你输入什么来关闭它。

        【讨论】:

          【解决方案9】:

          如果将来需要任何人,即使我是初学者并且对 Heroku 不太了解,您可能在 runtime.txt 文件中请求了堆栈不支持的版本。

          python-3.8.2 to python-3.8.10

          从 python-3.8.2 更改为 python-3.8.10 帮助我解决了这个问题。您可以在此处查看支持的堆栈:https://devcenter.heroku.com/articles/python-support

          【讨论】:

            【解决方案10】:

            我决定逐行阅读日志。 以下是部分错误日志:

            remote:        > gbt-ltd-website-frontend@0.1.0 build /tmp/build_c37edf59
            remote:        > react-scripts build
            remote:        
            remote:        Creating an optimized production build...
            remote:        Failed to compile.
            remote:        
            remote:        Cannot read property 'toLowerCase' of undefined
            remote:        CompileError: Begins at CSS selector .Styles_hone__1Uuf2
            remote:        
            remote:        
            remote: npm ERR! code ELIFECYCLE
            remote: npm ERR! errno 1
            remote: npm ERR! gbt-ltd-website-frontend@0.1.0 build: `react-scripts build`
            remote: npm ERR! Exit status 1
            ...
            remote: !       Push rejected to gbtstructurals.
            remote: 
            To https://git.heroku.com/gbtstructurals.git
             ! [remote rejected] master -> master (pre-receive hook declined)
            error: failed to push some refs to 'https://git.heroku.com/gbtstructurals.git'
            

            我从错误开始的地方开始阅读“npm ERR!code ELIFECYCLE”,并找到了错误的实际原因。这是一个 CSS 规则。我首先删除了规则并建立了它。然后我检查了我的声明,发现我自相矛盾。

            【讨论】:

              【解决方案11】:

              我想,这不会是由于任何应用程序或代码更改而发生的错误。 由于以下原因,我现在遇到了同样的问题:

              • 1) 我在 bitbucket/git 上有代码我将代码推送到存储库(这个 repo 与 heroku 应用程序相关联,这意味着对此将进行更改 反映在heroku上)
              • 2) 将代码推送到 repo 后,我正在尝试在 heroku 上推送代码 使用“git push heroku master”,但由于某种原因我中止了这个 命令,这就是为什么代码没有推送到heroku

              • 3) 然后我很高兴将代码推送到 heroku,它说同样的错误
                如上

              • 4) 解决方案是“只需拉出你最后提交的代码” 并将更改推送到 heroku ..谢谢

              【讨论】:

                【解决方案12】:

                我有一个 sinatra 应用程序。 (Heroku 确实支持 Sinatra)。

                heroku 博文中的说明不完整

                https://blog.heroku.com/32_deploy_merb_sinatra_or_any_rack_app_to_heroku

                我的程序在本地运行良好,但在尝试推送到 heroku 时出现错误。

                heroku 博文不包括制作 gemfile 和进行捆绑安装的需要。该程序在本地运行良好,但要使其在 heroku 上运行,它需要一个 Gemfile 并在其上安装包。

                https://teamtreehouse.com/community/how-can-i-make-my-sinatra-app-public 这里的这个链接提到我需要一个 Gemfile,并提到了 Gemfile 的内容。然后进行捆绑安装。然后,一旦完成,然后按照该 heroku 博客文章中的说明制作程序文件,以及 config.ru 和 git repo 并执行 heroku create(这也创建远程),然后 git push heroku master。

                树屋链接中提到的 Gemfile

                # define our source to look for gems
                source "http://rubygems.org/"
                
                # declare the sinatra dependency
                gem "sinatra" 
                

                然后 bundle install 来安装 Gemfile。

                bundle install
                

                hello.rb(如 heroku 博文中所述)

                require 'rubygems'
                require 'sinatra'
                
                get '/' do
                  "Hello from Sinatra on Heroku!"
                end
                

                config.ru

                require './hello'
                run Sinatra::Application
                

                混帐

                $ git init
                Initialized empty Git repository in /Users/adam/hello/.git/
                $ git add .
                $ git commit -m "sinatra and heroku, two great tastes"
                [master (root-commit)]: created 93a9e6d: "sinatra and heroku, two great tastes"
                 2 files changed, 9 insertions(+), 0 deletions(-)
                 create mode 100644 config.ru
                 create mode 100644 hello.rb
                

                heroku 创建

                $ heroku create
                Created http://severe-spring-77.heroku.com/ | git@heroku.com:severe-spring-77.git
                Git remote heroku added
                

                向heroku推送

                $ git push heroku master
                Counting objects: 4, done.
                Compressing objects: 100% (3/3), done.
                Writing objects: 100% (4/4), 385 bytes, done.
                Total 4 (delta 0), reused 0 (delta 0)
                
                -----> Heroku receiving push
                -----> Verifying repository integrity... done, looks like a Rack app.
                       Compiled slug size is 0.1MB
                -----> Launching....... done
                       App deployed to Heroku
                
                To git@heroku.com:severe-spring-77.git
                 * [new branch]      master -> master
                

                【讨论】:

                  【解决方案13】:

                  对我来说,这是 java app 中未使用的导入,删除了未使用的导入,一切正常。

                  【讨论】:

                    【解决方案14】:

                    在部署节点应用程序时遇到了同样的错误,但通过这两个步骤解决了,我想我会分享一下,以防其他人遇到同样的问题。

                    1. 确保您没有提交node_modules,因为heroku 在推送时会从package.json 安装依赖项。尝试将 node_modules/ 添加到您的 .gitignore 以确保您不会意外提交它
                    2. Heroku 使用 Node v12,node-sass 4.10.0 将无法使用该 Node v12 构建。尝试通过添加以下内容来增加 node-sass 版本。这使它能够为我成功构建:
                      "devDependencies": {
                        "node-sass": "^4.12.0"
                      }
                    

                    【讨论】:

                      【解决方案15】:

                      就我而言,我有一个名为“build”的 npm 脚本,其 as 值为 npm run build --prefix client

                      Heroku 自动执行 npm run build 命令,但它无法构建我的 React 应用程序。可能是因为 Heroku 没有安装 react-scripts 模块。

                      所以我将命令重命名为 build-client,现在我可以将更改推送到 Heroku。

                      【讨论】:

                        【解决方案16】:

                        检查您的配置变量(在 heroku 中)可能是个好主意。

                        当我为我的应用程序创建管道并想要推送到新创建的临时应用程序时,我收到了同样的错误消息。它不起作用,因为我之前设置的配置变量没有转移到新的登台应用程序(显然)。在我再次添加变量后,推送到 heroku git 再次完美无缺。

                        【讨论】:

                          【解决方案17】:

                          我最近的一个应用程序在运行后遇到了类似的问题:

                          git push heroku master
                          

                          错误:

                          remote:  !     Push failed
                          remote: Verifying deploy...
                          remote:
                          remote: !       Push rejected to stormy-escarpment-13653.
                          remote:
                          To https://git.heroku.com/stormy-escarpment-13653.git
                           ! [remote rejected] master -> master (pre-receive hook declined)
                          

                          问题是我在运行命令时位于错误的目录中。我需要位于应用程序的根目录中。 所以我运行了git rm --cached <app_name>,进行清理并再次运行,它按预期工作。

                          【讨论】:

                            【解决方案18】:

                            我的问题是我在推送之前忘记捆绑安装。

                            【讨论】:

                              【解决方案19】:

                              我遇到了这个问题(Heroku 出现同样的错误):

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

                              错误 我对代码进行了一些更改并删除了一些参数,显然我错过了一行简单的逗号 (,)。这导致了构建错误。推送时在控制台中看不到,只有“预接收挂钩被拒绝”错误。

                              解决方案 我修复了逗号问题,重建并推送到 Heroku,现在它可以工作了。

                              【讨论】:

                                【解决方案20】:

                                如果您的 css 中有错误,也会出现此错误。

                                在我提出的一个媒体查询中

                                @media screen adn (min-width: 1000px) {
                                

                                而不是给我这个错误的“and”。

                                如果您收到包含该消息的错误,则可能是这种情况的一个很好的指标

                                "Tasks: TOP => assets:precompile ... Precompiling assets failed" 
                                

                                这是我查看 CSS 的第一个线索。

                                【讨论】:

                                  【解决方案21】:

                                  尝试将 Node/php 或任何引擎更新到最新版本,然后再次部署,它肯定会工作。

                                  【讨论】:

                                    【解决方案22】:

                                    你需要在根目录中提及语言

                                    我是如何解决的

                                    我的python烧瓶没有提到requirments.text

                                    Heroku 检测

                                    Using buildpack: heroku/python
                                    remote: -----> Python app detected
                                    
                                    
                                    

                                    enter image description here

                                    【讨论】:

                                      猜你喜欢
                                      • 2020-03-12
                                      • 2015-04-03
                                      • 2019-10-16
                                      • 2020-07-19
                                      • 2012-03-21
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 1970-01-01
                                      • 2011-12-20
                                      相关资源
                                      最近更新 更多