1
0

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のコンフリクト(conflict)の解消方法について

Last updated at Posted at 2020-06-16

コンフリクトの基本

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

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

Rebase時のConflictの解消方法

操作コマンド

$ 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しているファイルがなければコミットされる

▼実行前

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

▼実行後

* 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の解消方法

操作コマンド

$ 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 ''

▼実行前

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

▼実行後

* 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の解消方法

操作コマンド

$ 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 ''

▼実行前

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

▼実行後

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?