LoginSignup
3
0

More than 3 years have passed since last update.

Git rebaseをする時、強制Pushをする理由

Posted at

rebaseの手順

git checkout [branch]
git rebase master

最新のbranchにPullした後、作業中のbranchにCheckoutします。
その後、master branchにrebaseします。
問題がないと、rebaseできます。
でも、人生は甘くないので、conflictや色んなエラーメッセージが出ます。

conflictが発生する時、解決方法

git status                //conflictされたファイルを確認

git add [修正したファイル]    //修正したファイルをaddする
git rebase --continue       //もう一度、rebaseする

git status               //conflictされたファイルを確認
git push                   //問題がないとpushする

こんな流れで、conflictされたファイルを修正しながら、rebaseします。
ファイルを修正して、問題がないとpushします。

pushしてエラーが発生した時、解決方法

git push
! [rejected]          branch -> branch (non-fast-forward)

問題がないはずなのに[non-fast-forward]という理由でrejecteされました。
そういう時は、強制Pushをすると解決できます。

git push -f [branch]

なぜ、強制Pushをしますか?

master   C0--C1--C2--C3--C6--C4(1)--C5(1)   
                      \  
branch                 C4--C5

簡単に言うと、普通の状態なら、作業branchとmaster branchの共通コミットとmaster branchのコミットまで全部コピーするので、エラーが出ます。

3
0
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
3
0