git rebase

では実際にrebaseをしてみましょう。feature4にて作業します。

git switch -c feature4

a.txtを以下のように修正しましょう。

a.txt
sample1
tarou
good evening
world
I come from Japan.

その後、git addgit commitをしましょう。

git add .
git commit

commit messageは以下とします。

a.txtに出身の文章を追加

mainに切り替えましょう。

git switch main

b.txtを以下のように編集します。

b.txt◎
sample2
tarou
good evening
hello
I come from Japan.

その後、git addgit commitをしましょう。

commit messageは以下とします。

では、feature1mainをrebaseします。

feature1に移動しましょう。

rebaseする前にgit logにて確認すると、以下のように表示されるかと思います。当然mainでの変更を含まれていません。

では以下のコマンドを叩きましょう。

再度git logにて確認すると、feature1でのcommitの前にmainでのcommitが追加されたかと思います。

rebaseに関しても、もし同じファイルの同じ行を編集していた場合は、conflictが起こり、conflictを解消する必要がありますが、この章ではその方法は説明しません。

Last updated