# git rebase

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

```bash
git switch -c feature4
```

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

<pre data-title="a.txt"><code>sample1
tarou
good evening
world
<strong>I come from Japan.
</strong></code></pre>

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

```bash
git add .
```

```bash
git commit
```

commit messageは以下とします。

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

`main`に切り替えましょう。

```bash
git switch main
```

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

<pre data-title="b.txt◎"><code>sample2
tarou
good evening
hello
<strong>I come from Japan.
</strong></code></pre>

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

```bash
git add .
```

```bash
git commit
```

commit messageは以下とします。

```
b.txtに出身の文章を追加
```

では、`feature1`に`main`をrebaseします。

`feature1`に移動しましょう。

```bash
git switch feature1
```

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

```bash
git log --oneline --graph
```

<figure><img src="https://1869761657-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcUBbYqol4PMzZJggiMqV%2Fuploads%2Fy2xbiQzH6MowvdIcNa4e%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202023-11-27%2015.42.49.png?alt=media&#x26;token=c2971288-1107-48f9-a7ec-1020df3d11b4" alt=""><figcaption></figcaption></figure>

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

```bash
git rebase main
```

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

```bash
git log --oneline --graph
```

<figure><img src="https://1869761657-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcUBbYqol4PMzZJggiMqV%2Fuploads%2FTzOB6mW1NeYEfiBqaGNS%2F%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88%202023-11-27%2015.44.17.png?alt=media&#x26;token=e214eacb-3b55-4994-8e83-9c1c529d5c2c" alt=""><figcaption></figcaption></figure>

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