Merge conflicts

Git ระดับกลาง

George Boorman

Curriculum Manager, DataCamp

Conflicts

  • Conflict

    • ไม่สามารถแก้ไขความแตกต่างของเนื้อหาในไฟล์หนึ่งไฟล์หรือมากกว่าระหว่าง branch ได้
  • แก้ไขไฟล์เดียวกันใน 2 branch

  • พยายาม merge

  • Git ไม่รู้ว่าควรเก็บเวอร์ชันไหน

  • Conflict!

Git ระดับกลาง

เวอร์ชันที่ขัดแย้งกันของ README.md

documentation branch

# 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 branch

# Contents and usage

This repo contains source code 
for the DataCamp website.

It is for internal use only, 
external access is prohibited.
Git ระดับกลาง

การ merge

  • จาก main branch
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 ที่แสดงส่วน conflict โดยใช้ nano

Git ระดับกลาง

ไวยากรณ์ conflict ของ Git

ไฟล์ conflict ที่มีคำอธิบายแสดงเนื้อหาใน main branch และ documentation branch

Git ระดับกลาง

แก้ไข conflict

nano web editor ที่ลบ Git syntax <<<<<<< documentation, =======, และ >>>>>>> HEAD ออก

  • บันทึก: Ctrl + O (ไม่ใช่ Ctrl + 0) แล้วกด Enter
  • ออก: Ctrl + X
Git ระดับกลาง

การ merge branch

  • merge เมื่อแก้ไข conflict เรียบร้อยแล้ว
git add README.md
git commit -m "Resolving README.md conflict"
git merge documentation
Already up to date.
  • ป้องกันดีกว่าแก้ไข!
Git ระดับกลาง

มาฝึกกันเถอะ!

Git ระดับกลาง

Preparing Video For Download...