LoginSignup
1
3

More than 1 year has passed since last update.

git push の際にpre-receive hook decliedというエラーが出たときの対処

Posted at

環境

OS: Windows10

$ php -v
PHP 8.0.9 (cli) (built: Jul 29 2021 14:12:27) ( NTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies

$ chocolatey -v
0.10.15

$ php artisan --version
Laravel Framework 7.30.4

事象

Herokuにアプリを作成してgit pushしようとしたら以下のエラーが発生してpushが完了できない。


// 省略
remote:  !     Push failed: cannot parse Procfile.
remote:  !     Please try pushing again.
remote:  !     If the problem persists, see https://help.heroku.com/ and provide Request ID eab36261-ec85-5190-cec3-fa34be370f7b.
remote:
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to appname.
remote:
To https://git.heroku.com/appname.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/appname.git'


原因

Procfileの文字コードがUTF16になっていた。

Procfileの作成時のコマンド

VSCodeのTERMINALタブで以下のコマンドを実行してProcfileを作成した。
console
echo "web: vendor/bin/heroku-php-apache2 public/" > Procfile

紆余曲折

調べたキーワード

// これで調べまくったけど、無限にうまく行かなかった
pre-receive hook declined

試したこと

①herokuのアプリを削除して、別の名前でherokuアプリを作成 → git push
②ダミーのファイルを作成してgit add . からpushまで
③pull してからpush

pre-receive hook declinedで調べると上記のような対策が出てくる。けど、検討違いでした。
調べるべきは


Push failed: cannot parse Procfile.

解決策が見い出せた記事が↓↓↓↓
https://teratail.com/questions/197422

先人たちに感謝!

とりあえずVSCodeでProcfileを開いて文字コードを変更しました。
右下あたりに次の画像のような部分に文字コードが表示されています。

image.png

UTF-8ってところがUTF-16になっていたので、その部分をクリック。すると上の方に文字コードが選べるようなものが出てくるのでUTF-8を選択。

文字化けするので全部削除してもう一度下記内容を手打ちする。

web: vendor/bin/heroku-php-apache2 public/

これでpushができるようになります!!!

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3