コンフリクト

Git中級

George Boorman

Curriculum Manager, DataCamp

コンフリクト

  • コンフリクトとは

    • ブランチ間でファイルの内容に差異があり、どちらが正しいか判断できない状態
  • 同じファイルを2つのブランチで編集

  • マージを実行

*Gitはどのバージョンが正しいのか判断できない

  • これがコンフリクト!
Git中級

README.mdのバージョンコンフリクト

documentationブランチ

# Contents and usage

This repo contains source code 
for the DataCamp website.

It also contains source code for an 
AI-Assistant (recommendation system) 
that takes prompts from learners and 
returns suggested content
that they might be interested in. 

It is for internal use only, 
external access is prohibited.

mainブランチ

# Contents and usage

This repo contains source code 
for the DataCamp website.

It is for internal use only, 
external access is prohibited.
Git中級

マージを実行する

  • mainブランチから
git merge documentation
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
Git中級

ファイルを開く

nano README.md

READMEファイルがnanoでコンフリクトセクションを表示している

Git中級

Gitコンフリクト構文

mainブランチとdocumentationブランチの内容を示す注釈付きコンフリクトファイル

Git中級

コンフリクトの解消

nano WebエディターでGitの構文 <<<<<<<、=======、>>>>>>> HEADを削除している様子

  • ファイル保存:Ctrl + OCtrl + 0ではない)、その後Enter
  • 終了:Ctrl + X
Git中級

ブランチをマージする

  • コンフリクト解消後に、もう一度マージする
git add README.md
git commit -m "Resolving README.md conflict"
git merge documentation
Already up to date.
  • 予防は最大の防御!
Git中級

練習しましょう!

Git中級

Preparing Video For Download...