Xung đột hợp nhất

Git nâng cao

George Boorman

Curriculum Manager, DataCamp

Xung đột

  • Xung đột

    • Không thể hòa giải khác biệt nội dung của một hoặc nhiều tệp giữa các nhánh
  • Chỉnh cùng một tệp trên hai nhánh

  • Thử hợp nhất

  • Git không biết giữ phiên bản nào

  • Xung đột!

Git nâng cao

Phiên bản README.md xung đột

Nhánh 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.

Nhánh main

# Contents and usage

This repo contains source code 
for the DataCamp website.

It is for internal use only, 
external access is prohibited.
Git nâng cao

Hợp nhất

  • Từ nhánh 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 nâng cao

Mở tệp

nano README.md

tệp README hiển thị các phần xung đột trong nano

Git nâng cao

Cú pháp xung đột Git

tệp có chú thích cho thấy nội dung trên nhánh main và nhánh documentation

Git nâng cao

Giải quyết xung đột

trình soạn thảo web nano xóa cú pháp Git <<<<<<< documentation, =======, và >>>>>>> HEAD

  • Lưu: Ctrl + O (không phải Ctrl + 0), rồi Enter
  • Thoát: Ctrl + X
Git nâng cao

Hợp nhất các nhánh

  • Hợp nhất sau khi đã giải quyết xung đột
git add README.md
git commit -m "Resolving README.md conflict"
git merge documentation
Already up to date.
  • Phòng ngừa luôn tốt hơn chữa!
Git nâng cao

Let's practice!

Git nâng cao

Preparing Video For Download...