1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Git】git rebase エラー対処法|First, rewinding head to replay your work on top of it... Fast-forwarded master to origin.

Last updated at Posted at 2021-03-19

他のブランチの変更内容を自分のブランチの過去履歴に取り込む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してください言われる)

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?