LoginSignup
33
22

More than 1 year has passed since last update.

『 ! [rejected] master -> master (non-fast-forward) 』のせいでpushできねぇッ!!

Last updated at Posted at 2019-03-20

補足

学んだ知識のほとんどは,Qiitaではなくこちらにバーッとまとめております.

今回のエラー

コミットメッセージを修正したので、

$ git commit --amend -m "add #0 xxxさんのREADMEを追加"
[master 41cc21b] add #0 xxxさんのREADMEを追加
 Date: Wed Mar 20 20:54:34 2019 +0900
 1 file changed, 193 insertions(+)
 create mode 100644 README.md

pushしたら、 ! [rejected] master -> master (non-fast-forward)が表示されてしまう。

$ git push
To github.com:Hiroki-IT/Symfony2_Nyumon.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Hiroki-IT/Symfony2_Nyumon.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.

原因

ブランチの状態には、fast-forward型と、
アジャイルSEを目指すブログ1.png

non fast-forward型があり、
アジャイルSEを目指すブログ2.png

ローカルでは、コメント変更前のブランチから変更後ブランチが作られてnon fast-forward型となっており、それをpushしようとしたためエラーになったみたい。

引用元:アジャイルSEを目指すブログ,http://d.hatena.ne.jp/sinsoku/20111025/1319497900
引用元:NullNote,https://nullnote.com/web/git/merge_rebase/

解決法

ローカルのコメント変更前ブランチと変更後ブランチをmergeする。

##(1)履歴の異なるブランチをmerge
引数として、--allow-unrelated-historiesをつけることで、履歴の異なるブランチ同士をマージさせることが可能。
今回は、ローカルのコメント変更前ブランチと変更後ブランチをmerge

$ git merge --allow-unrelated-histories
Merge made by the 'recursive' strategy.

※補足
--allow-unrelated-historiesをつけないと、無関係の履歴をmergeすることはできないと表示される。

$ git merge
fatal: refusing to merge unrelated histories

##(2)pushを実行

$ git push
Enumerating objects: 2, done.
Counting objects: 100% (2/2), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 333 bytes | 111.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To github.com:Hiroki-IT/Symfony2_Nyumon.git
   f81c813..f17f68e  master -> master

//成功

引用リンク

33
22
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
33
22