git push時にエラー
git push した後に直前のcommit内容を正しく変更することになり、ammendオプションで変更しました。その後再度pushをすると次のようなエラーが発生。
! [rejected] develop/bootstrap_navbar -> develop/bootstrap_navbar (non-fast-forward)
error: failed to push some refs to '省略'
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.
理由:自分がリモートの変更をpullしてから、pushするまでの間に、他からのpushがあるなどしてリモートが変更されている状況。エラーメッセージが教えてくれているように、あなたのブランチの先端はリモートのより後ろになっている。リモートの変更をマージしてから、改めてpushする。参考:git
対応方法
私の場合は先にpushした内容に変更がないのでrejectされたのかなーと思いました。(間違っていたら指摘お願いします。)ご指摘を受けました。yamap_55さんありがとうございます。
git pushした後にammendオプションでコメントを変更したことで、コミットハッシュが変更されています。具体的にはリモートが「A → B」とコミットハッシュがある時にammendオプションで「A → C」と変更し、このツリーをpushしようとしたため、remoteの先頭コミットのハッシュがBなのに、ローカルのツリーにはBというハッシュがないよ!とエラーになっています。次のコマンド(-fオプション)で強制的にpushしました。
git push origin [ローカルブランチ名] -f
感想
現在共同開発でgitを使うことが多くなったので勉強になります。