shuhelohelo’s blog

Xamarin.Forms多めです.

git rebase ブランチ

今いるブランチ全体(ブランチの枝分かれから全部)を指定したブランチに付け替える

ほんと?

f:id:shuhelohelo:20190714155440p:plain

b1ブランチをmasterブランチの先頭にくっつけてみる。

予想では、枝分かれしたところから先頭までなので、commit3, 8がmasterの先頭にくっつくはず。

f:id:shuhelohelo:20190714155601p:plain

$ git rebase master b1
First, rewinding head to replay your work on top of it...
Applying: commit2
Using index info to reconstruct a base tree...
M       AspNetCorePractice/Program.cs
Falling back to patching base and 3-way merge...
Auto-merging AspNetCorePractice/Program.cs
Applying: commit3
Applying: commit8

結果。

f:id:shuhelohelo:20190714160041p:plain

間違ってた。

masterとb1にとっての分岐はここ。

f:id:shuhelohelo:20190714160324p:plain

だからcommit2も含まれるんだな。

なるほど。

追加

じゃあ、この状態からb1をb2にrebaseすると、どこからどこまでがくっつくのか。

git rebase b2 b1

commit1, 4, 5, 2, 3がb2にくっつきました。

やっぱりこれもb1とb2の分岐から移動になるんだな。

f:id:shuhelohelo:20190714162039p:plain

b1とb2にはそれぞれcommit2が含まれていたけれど、rebase後には1つしかない。

同じコミットは重複しないようになっている、と。