他のブランチの変更内容を自分のブランチの過去履歴に取り込むgit rebase
でFirst, rewinding head to replay your work on top of it...が出た時の理由と対処法。
エラー内容
$ git rebase origin master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to origin.
[要約]まず、あなたのブランチの最新のコミットにHEADを移動させてください(巻き戻す)
そこから、fast-forwardしてください。
## 発生原因 取り込もうとしているブランチと自分の**ブランチが分岐していないため**。
git rebase <ブランチ>
は分岐している指定したブランチの内容を自分の最新のコミットの直前にとってつける処理なので。
分岐していない場合は、そもそもrebaseする必要がない。
### 分岐していないコミットの例
A---B---C---D---E master
↑
自分のブランチ
または
C---D---E master
/
A---B---F---G 他人のブランチ
↑
自分のブランチ
この場合、masterブランチを取り込むには、自分のHEADをmasterの位置に移動すればいいだけ。
前に移動するので、fast-forward
と呼ぶ。
対処法
・git merge <ブランチ名>
で自分のコミットを前に進めることができる。
git merge master
or
git merge origin master
### 実例 まずは現状。masterのHEADは4つ前にある。分岐はしていない。
$ git log --oneline
# masterの状況
57776bc (HEAD, origin/master, origin/HEAD, master) [add] article page: review
34db962 [add] article page: header
988381d [add] article page: cv btn
2a21e0a [add] article page: table
# 今ここ
3e4e2b0 (origin/topic, topic) [F]json-ld route('index')
▼fast-worwardを実行
fast-worwardという名前がややこしいが、ただマージするだけ。
$ git merge origin master
Updating 3e4e2b0..57776bc
Fast-forward
# headが移動
57776bc (HEAD, topic, origin/master, origin/HEAD, master) [add] article page: review
34db962 [add] article page: header
988381d [add] article page: cv btn
2a21e0a [add] article page: table
3e4e2b0 (origin/topic) [F]json-ld route('index')
(origin/topic) を合わせるには、以下を実行すればOK。
$ git push origin topic
$ git fetch
## (参考)rebaseの処理結果 rebaseの処理結果は以下のようになる。
C---D---E master
/
A---B---F---G 自分のブランチ
↓ git rebase master
master
C---D---E---F'---G' 自分のブランチ
/
A---B
以下と同じ
master
A---B---C---D---E---F'---G' 自分のブランチ
これがrebase処理なので、分岐してなければrebaseは不要。(fast-forwardしてください言われる)