Конфлікти злиття

Середній рівень Git

George Boorman

Curriculum Manager, DataCamp

Конфлікти

  • Конфлікт

    • Неможливо узгодити відмінності у вмісті файлів між гілками
  • Редагуєте той самий файл у двох гілках

  • Намагаєтесь злити

  • 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 видаляє синтаксис Git <<<<<<< documentation, ======= та >>>>>>> HEAD

  • Зберегти: Ctrl + O (не Ctrl + 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...