Peta dunia

 

EN: Read in English

Dunia 3: Alam Selari

Baca penanda konflik

Anda akan belajar: kenapa merge berhenti, dan cara baca penanda konflik Git.

Teks BM belum disemak oleh penutur asli.

Masalahnya

git merge cake papar: Auto-merging index.html. CONFLICT (content): Merge conflict in index.html. Automatic merge failed. Output terminal: $ git merge cake Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.

Anda merge cake ke main, dan Git berhenti. CONFLICT! Adakah anda dah rosakkan diari?

Tengok

main dan cake masing-masing ada commit baru. Merge berhenti: lencana merah Conflict dengan tanda amaran muncul di bawah HEAD.
6d3a9b1a8feb63270a76e0c66136013a957

Tiada apa yang rosak. Kedua-dua branch tulis hari 2 yang berbeza pada baris sama. Itulah konflik (conflict): Dua perubahan bertembung di tempat sama.. Git tak boleh teka, jadi ia tanya anda.

Tengok

index.html kini ada kedua-dua baris hari 2, di antara tiga baris penanda. Output terminal: $ git merge cake Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. $ cat index.html <h1>My Diary</h1> <p>Day 1: I learned Git.</p> <<<<<<< HEAD <p>Day 2: I learned branches.</p> ======= <p>Day 2: I baked a cake.</p> >>>>>>> cake

Git tulis kedua-dua versi ke dalam fail. penanda konflik (conflict markers): Baris <<<<<<<, ======= dan >>>>>>> yang Git letak di sekeliling pertembungan. memagarinya. Baris anda di atas. Baris mereka di bawah.

Cuba

Cari pagarnya.

Ketik tiga baris penanda.

~/diary $ git merge cake~/diary $ cat index.html

0 daripada 3 dijumpai

Teka

Baris hari 2 mana yang datang dari branch anda, main?

Pilih satu jawapan.

Semak

git status kata: You have unmerged paths. Di bawah Unmerged paths: both modified: index.html. Output terminal: $ git merge cake Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. $ git status On branch main You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a")

Keliru di tengah merge? Jalankan git status. Ia senaraikan fail yang perlu dibaiki sebagai both modified. Ia siap beritahu langkah seterusnya.

Anda berjaya!

Kini anda boleh baca penanda konflik tanpa panik.

Nak tahu lebih (pilihan)

Semasa konflik, git diff tunjuk kedua-dua pihak sekali gus. Nak tengok baris sebelum mana-mana perubahan? Jalankan git config --global merge.conflictStyle diff3. Lepas itu, bahagian yang bermula dengan ||||||| tunjuk baris asal.

git diff semasa konflik: diff gabungan dengan kedua-dua baris hari 2 dan penanda. Output terminal: $ git merge cake Auto-merging index.html CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result. $ git diff diff --cc index.html index efaaee0,f4c5ff0..0000000 --- a/index.html +++ b/index.html @@@ -1,3 -1,3 +1,7 @@@ <h1>My Diary</h1> <p>Day 1: I learned Git.</p> ++<<<<<<< HEAD +<p>Day 2: I learned branches.</p> ++======= + <p>Day 2: I baked a cake.</p> ++>>>>>>> cake