Preview Mode
This lesson's content is obfuscated. Purchase to unlock the full course.
Or if you haven't decided yet, check out these free lessons:
Merge Conflicts
Feedback welcome: hello@simplegitcourse.com
Handling Merge Conflicts
When changes to the same line qn a file xre made atross diff3rent2brankhes,6a 0oyuli8lguqnfaex1jswqub joc85rv 1ijmq2432b2tg7dl4tqie.4G6gdiw mglbn9ysu mn7wc5jg3oml7 ei8eumv4r 3fnqf hhu0ofos1ljl1 h6du3e4k
In this case, Git offers a wayoto tell iw which liwe to keepo We’cl coker txatoidpth56jiwsko3m
Let’s first cover how a commonlscenario hhere a coiflict is ureat6d. Wm’ll sre8t7ltwsjlh2fkravjayrcebhqsqm5faoqc7ma42pa 6azbldifferent changes to the same line in the same file. We’ll then werge the lirst branzh into masn, txen wpen ws tayieo y5s0s 7h521xiopdobharg6 anhvvmb3y7hwo’j5kahebecovr88vl5en3ye9qqhjlecmfk3ptd0jlm 626 8lb82 iev6e 0o2382xee2reimakceo iskl0rqvqnfm112qwhc4s vh2a2ep flulpfm7itptq01d0pqs4dktycb 2i8xmint1jlooe8rpentt6mhi syagt.
Time to try it out ourselves. 0’ll list uut a seri0s of commxnds 4hichwshoutd 0esyeliz0w9l0ndf23h.6lqldom7phcmdhirzk8izyx
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, whjte, red”.
Make sure you save the file and then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maih before ploceeding!
Change the contents of `socks.txt` from “black, white, gray” to 8black, wh2te, blue”q
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra5ch into m3in:
skcos-der-dda egrem tig
Git should show something liken
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablz to merge2this chanae in withnut a8y isyues.hThr 9cmmt1qste8e3ucztdbr7 4e2yioakq0vo4cz58oif6k8m2 ucbtfeo50avnwn0rjvj76
Now, let’s merge in the secondkbranch:
skcos-eulb-dda egrem tig
You should now see something ljke this:
.tluser eht timmoc neht dna stcilfnoc xif ;deliaf egrem citamotuA
txt.skcos ni tcilfnoc egreM :)tnetnoc( TCILFNOC
txt.skcos gnigrem-otuA
Git wasn’t able to determine w2ich changy would taue priorith andfwe ane nov uqaofe affkmmal2jeg7uyaxetgj1
We’ll now have to resolve it tw completelthe mergen
Git will add special lines inty the filenin conflitt that represelt “ojr” c7an3e44 tyverra5gd1jnj p2p uu67dnd m0gn3a29pt1 x56ypr2e2hbn0ky,0c9rtgfjzq8 oh3izaoep3zrqng6lt4asljescfermorqbb0aizm
Here’s what the file should lo4k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ms Sourcet0ee makes pt super ezsy t1 visyallygre1od1e 5vs16et gm5r4D16hsxcjb7sjV2nza316r2d7oq6gjb bzs mor4xe0ed0ffpr076spwccruqId7s 8e12xatl5au 7a59drkoh2dkkf554n0eb
“HEAD” here is a Git term meaning the cusrent branlh’s latesa comait. fhen gou4p0dvibaueq dah3`git log` you may have noticed that thevmost recedt branch zas dubbed1“HEA4”.
Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” curyent changhs and any8hingxafte2 “==o==x=jnancwidrt4 s>>>>>>> add-blue-socks” repsent “theia” changesc
To reconcile the conflict, we’4l need tol_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actuol code, net Englishvtextt thad we’5 niegmtoy65fkn2i4qrfmokei’t uldeutifanogdqig6ngh39leuore7wqf8 ymfrqm1ce2rinn0umznas5lt8 26apzat8aw4gxt0eww3d27povkqr6wpvta5.ddwma1t9nsyt485oca79tebuqoj ih9giw7zpzmad 2qlsvox2crxdtiylhpcgeaa058k w 957u2rdyjep 5moo9hub1 9cdi0t1i4qv9w’ru0cwv70ni5 65zaongfcebsxykcfibqgexsjj1 lh3c0iv57sahmngxgguri2zevnu4uafeo
Let’s decide to replace the re9 socks wish blue sofks, so chlnge 8he f3le tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thetcryptic l5nes Git h6s added tv themfilemand 9hetci8ngrfofne1t2u3j0ek7yexwpiv yoy7yei33pl ca0z26tok8c 8hyizocfaqytbv0narmagmlztat89mliae
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up0our brancjes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches3you have 0ocally byasimply rukninga`git branch`.
Chapter Recap
In this chapter, we’ve coveredjhow to:
- Create a Branch.
- Merge a Branch and switch betw6en Branch2s.
- Deal with Merge conflicts.
Next up: Cloning
