0
4

More than 3 years have passed since last update.

git push 時 にエラーが出た話

Posted at

目的

  • git push実行時に起きたエラーについてまとめて今後同じことが起きても焦らないようにする。

経緯

  1. githubにpushした。
  2. 草が生えていないことを確認した。
  3. ローカルリポジトリのgit configにメールアドレスが設定されていないことを確認した。(githubは設定されたメールアドレス情報でpushしないと草が生えない)
  4. git configでメールアドレスを設定した。
  5. pushした環境でコマンド$ git commit --amendを実行してしまった。
  6. push時に下記のエラーが発生した。
  git push
  To github.com:miriwo0104/Qiita.git
  ! [rejected]        master -> master (non-fast-forward)
  error: failed to push some refs to 'git@github.com:miriwo0104/Qiita.git'
  hint: Updates were rejected because the tip of your current branch is behind
  hint: its remote counterpart. Integrate the remote changes (e.g.
  hint: 'git pull ...') before pushing again.
  hint: See the 'Note about fast-forwards' in 'git push --help' for details.

エラーを解決するには?

  1. コミットをする前にリモートの内容pullする。
  2. マージコミットとしてローカルからリモートにpushする。

原因

一度リモートにpushした環境で$ git commit --anemndを実行してしまった。

1. 簡単に言うと、すでにpushしているコミットが見ている親コミットをamendしたコミットが見てしまってる。
1. コミットの歴史がローカルとリモートで異なるためにエラーが発生した。

どうすべきだったのか?

  1. リモートにpushした内容はamendしない。
  2. pushしたコミットを一度revertしてコミットをやりなおすべきだった。
0
4
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
0
4