Gitのコンフリクト(conflict)の解消方法について

# コンフリクトの基本

コンフリクト時のファイルの見方

```shell
<<<<<<< HEAD
This is an apple.      # mergeする側の変更(masterブランチの編集)
=======
This is an orange.     # mergeされる側の変更(testブランチの編集)
>>>>>>> test
```

# Rebase時のConflictの解消方法

操作コマンド

```shell
$ git checkout master

$ git rebase -i 2a87bbe

$ vim {file_name}

<<<<<<< HEAD
This is an apple.      # masterブランチの編集
=======
This is an orange.     # testブランチの編集
>>>>>>> test

$ git add {file_name}      # conflictを解消したファイルの名前をgitに教えてあげる

$ git rebase --continue    # これ以上conflictしているファイルがなければコミットされる
```

▼実行前

```shell
* 82ca154 - edit an apple (HEAD -> master) (3 seconds ago:2020-06-16 15:19:36 +0900) <Erika>
| * 2a87bbe - edit an orange (test) (60 seconds ago:2020-06-16 15:18:39 +0900) <Erika>
|/  
* 41ab24c - add test.txt (3 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (4 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```

▼実行後

```shell
* 5825464 - edit conflicts (rebase an apple and an orange) (HEAD -> master) (36 seconds ago:2020-06-16 15:56:16 +0900) <Erika>
* 2a87bbe - edit an orange (test) (38 minutes ago:2020-06-16 15:18:39 +0900) <Erika>
* 41ab24c - add test.txt (40 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (5 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```

# merge --squash時のconflictの解消方法

操作コマンド

```shell
$ git merge --squash test
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Squash commit -- not updating HEAD
Automatic merge failed; fix conflicts and then commit the result.

$ git st

$ vim test.txt

<<<<<<< HEAD
This is an apple.      # masterブランチの編集
=======
This is an orange.     # testブランチの編集
>>>>>>> test

$ git add test.txt

$ git commit -m ''

```

▼実行前

```shell
* 82ca154 - edit an apple (HEAD -> master) (3 seconds ago:2020-06-16 15:19:36 +0900) <Erika>
| * 2a87bbe - edit an orange (test) (60 seconds ago:2020-06-16 15:18:39 +0900) <Erika>
|/  
* 41ab24c - add test.txt (3 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (4 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```

▼実行後

```shell
* 95a1712 - edit conflicts (HEAD -> master) (3 seconds ago:2020-06-16 15:36:43 +0900) <Erika>
* 82ca154 - edit an apple (17 minutes ago:2020-06-16 15:19:36 +0900) <Erika>
| * 2a87bbe - edit an orange (test) (18 minutes ago:2020-06-16 15:18:39 +0900) <Erika>
|/  
* 41ab24c - add test.txt (20 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (4 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```

# merge時のconflictの解消方法

操作コマンド

```shell
$ git merge test
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

$ git st

$ vim test.txt

<<<<<<< HEAD
This is an apple.      # masterブランチの編集
=======
This is an orange.     # testブランチの編集
>>>>>>> test

$ git add test.txt

$ git commit -m ''
```

▼実行前

```shell
* 82ca154 - edit an apple (HEAD -> master) (3 seconds ago:2020-06-16 15:19:36 +0900) <Erika>
| * 2a87bbe - edit an orange (test) (60 seconds ago:2020-06-16 15:18:39 +0900) <Erika>
|/  
* 41ab24c - add test.txt (3 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (4 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```

▼実行後

```shell
*   f4c1675 - edit conflicts (HEAD -> master) (3 seconds ago:2020-06-16 15:29:26 +0900) <Erika>
|\  
| * 2a87bbe - edit an orange (test) (11 minutes ago:2020-06-16 15:18:39 +0900) <Erika>
* | 82ca154 - edit an apple (10 minutes ago:2020-06-16 15:19:36 +0900) <Erika>
|/  
* 41ab24c - add test.txt (13 minutes ago:2020-06-16 15:16:46 +0900) <Erika>
* 5f09f67 - initial commit (origin/master) (4 hours ago:2020-06-16 11:10:42 +0900) <Erika>
```