質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
terminal

Terminalは、Apple社のmacOSに標準で付属しているUNIX端末エミュレータ。UNIXコマンドによってMacの操作および設定を行うことができます。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Q&A

解決済

2回答

2767閲覧

Herokuに更新内容をデプロイしたいが、コミットできない

Murasaki_PurPle

総合スコア37

terminal

Terminalは、Apple社のmacOSに標準で付属しているUNIX端末エミュレータ。UNIXコマンドによってMacの操作および設定を行うことができます。

Git

Gitはオープンソースの分散バージョン管理システム(DVCS)です。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

0グッド

0クリップ

投稿2020/10/09 16:34

編集2020/10/10 02:00

Herokuに更新内容をデプロイしたいが、できない

GitでHerokuに作成したスクリプトをdeployしたいのですが、なぜか最後に

Git

1deploy % git push heroku master 2To https://git.heroku.com/test-greeting.git 3 ! [rejected] master -> master (fetch first) 4error: failed to push some refs to 'https://git.heroku.com/test-greeting.git' 5hint: Updates were rejected because the remote contains work that you do 6hint: not have locally. This is usually caused by another repository pushing 7hint: to the same ref. You may want to first integrate the remote changes 8hint: (e.g., 'git pull ...') before pushing again. 9hint: See the 'Note about fast-forwards' in 'git push --help' for details.

というエラーが発生し、解決できず作業が難航しております。

今、Twitterのbotを作成中です。
csvから文字列を読み取ってそれをツイートするだけのごく簡単なものです。
pythonでスクリプトを書いています。書いたスクリプトとcsvををHerokuにデプロイし、HerokuSchedulerで自動的に実行させるだけなのですが、その前段階のGitでHerokuにデプロイする作業で難航しています。

実際にTerminal上で書いたスクリプト

環境 使用アプリケーション
Terminal
Git
Heroku

現在、「deoloy」という名のディレクトリに
・AutoTweetByCSV.py
・requirements.txt
・tweetdata.csv
・.env
・.gitignore
というファイルが存在しています。

Herokuにログインします。

terminal

1 % heroku login 2 3Logging in... done 4Logged in as xxxx

次に、gitを初期化し Heroku上で作成したアプリケーション「test-greeting」に入ります。

Git

1deploy % git init 2Initialized empty Git repository in /Users/xxxx/Desktop/csvTweet/deploy/.git/ 3deploy % heroku git:remote -a test-greeting 4 › Warning: heroku update available from 7.42.5 to 7.44.0. 5set git remote heroku to https://git.heroku.com/test-greeting.git

状況を確認します。

Git

1deploy % git status 2On branch master 3 4No commits yet 5 6Untracked files: 7 (use "git add <file>..." to include in what will be committed) 8 AutoTweetByCsv.py 9 requirements.txt 10 tweetdata.csv 11 12nothing added to commit but untracked files present (use "git add" to track)

deployしたいファイルを追加し、状況を確認ます。

Git

1deploy % git add . 2deploy % git status 3On branch master 4 5No commits yet 6 7Changes to be committed: 8 (use "git rm --cached <file>..." to unstage) 9 new file: AutoTweetByCsv.py 10 new file: requirements.txt 11 new file: tweetdata.csv

コミットし、状況を確認します。

Git

1deploy % git commit -am "test" 2[master (root-commit) 0c4a89b] test 3 3 files changed, 257 insertions(+) 4 create mode 100644 AutoTweetByCsv.py 5 create mode 100644 requirements.txt 6 create mode 100644 tweetdata.csv 7 8deploy % git status 9On branch master 10nothing to commit, working tree clean

masterブランチに反映させます。

Git

1deploy % git push heroku master 2To https://git.heroku.com/test-greeting.git 3 ! [rejected] master -> master (fetch first) 4error: failed to push some refs to 'https://git.heroku.com/test-greeting.git' 5hint: Updates were rejected because the remote contains work that you do 6hint: not have locally. This is usually caused by another repository pushing 7hint: to the same ref. You may want to first integrate the remote changes 8hint: (e.g., 'git pull ...') before pushing again. 9hint: See the 'Note about fast-forwards' in 'git push --help' for details.

今までだと、これでデプロイが完了していたのですが 最後のエラー文が解決できず作業が止まっています。

試したこと

ディレクトリをイチから作り直し、同様の作業を行いましたが 実現できませんでした。
###補足(2020/10/10)
回答を頂いたので、試しにやってみました。その結果を書いておきます。

Git

1deploy % git pull heroku master 2warning: no common commits 3remote: Counting objects: 35, done. 4remote: Compressing objects: 100% (35/35), done. 5remote: Total 35 (delta 14), reused 0 (delta 0) 6Unpacking objects: 100% (35/35), done. 7From https://git.heroku.com/test-greeting 8 * branch master -> FETCH_HEAD 9 * [new branch] master -> heroku/master 10fatal: refusing to merge unrelated histories 11 12deploy % git push heroku master 13To https://git.heroku.com/test-greeting.git 14 ! [rejected] master -> master (non-fast-forward) 15error: failed to push some refs to 'https://git.heroku.com/test-greeting.git' 16hint: Updates were rejected because the tip of your current branch is behind 17hint: its remote counterpart. Integrate the remote changes (e.g. 18hint: 'git pull ...') before pushing again. 19hint: See the 'Note about fast-forwards' in 'git push --help' for details.

同様のエラーが出ました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

ローカルで git init を行っているように見えますが、すでに heroku 上の master には何らかのファイル置いてあるのではないでしょうか?
ローカルと heroku 上の master の歴史が違うため、push も pull もできなくなっているように見えます。

そのため、git rebase heroku/master と実行し、heroku 上の master から今の master が伸びている状態にしてあげれば git push できるようになるかと思います。

投稿2020/10/15 10:35

komem3

総合スコア27

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Murasaki_PurPle

2020/10/16 02:04

回答ありがとうございました。 無事動作を確認いたしました。助かりました。ありがとうございます????
komem3

2020/10/16 02:20

無事動いたのでしたら良かったです????
guest

0

git pull heroku master
これをした後に、
git push heroku master
これをするとどうなりますか?

投稿2020/10/10 01:33

firegrape

総合スコア902

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Murasaki_PurPle

2020/10/10 01:57

firegrapeさん 回答ありがとうございます。 確認したところ、同様のエラーが発生しました。 詳細は質問に追加で書いておきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問