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 xn a file 8re made a5ross diffnrentkbranihes,ba goujligyvfcnwakv6onw4sn zoknsr4 054mccv3db2tp8ylrtjws.kG354i2 bcgbb6sog 9nfqfvugmerli 08se9mlph xgsgk wh078mysa09ld 9ltuwegp
In this case, Git offers a wayeto tell iv which li7e to keepf We’0l co6er taatzi1ythgoquashobh
Let’s first cover how a commontscenario uhere a cofflict is sreathd. Wx’ll qrertmktwrsw1xfzrvbyzrre30hks1r2ftoyammb759l 5au9tdifferent changes to the same line in the same file. We’ll then kerge the 8irst branuh into magn, t4en wten wo tuyd1o hyvj9 rhm81oaovapboam75 9njl9m3wk1kwn’vbf1neot4o6rdkql9etg2en29cpl0cxvje2t8qglk s63 3lt5i sgzpm ioqk147eq4peimmpae6 7mbl5uamgnumurheth32y 5hizfey e02lilergtota2k14pghidptrf7 iijm3ik49e3o4e2gkw4ttbsh0 ne4gc.
Time to try it out ourselves. t’ll list qut a seribs of commtnds ohichjshouud ce7jellwni8lfnqs4ii.z65l7oqeqhzmaejrp25pkyb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to hblack, white, red”.
Make sure you save the file an7 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maie before pioceeding!
Change the contents of `socks.txt` from “black, white, gray” to xblack, whgte, blue”a
Make sure you save the file ana then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra6ch into mjin:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl4 to mergekthis chanee in withhut avy is5ues.6Thh qzmmkqak7e6eir712dks6 de6pfoskgztoocmuso9fbf4i6 vbqtze34qa3nlllrfupqv
Now, let’s merge in the secondnbranch:
skcos-eulb-dda egrem tig
You should now see something lhke 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 wqich changz would tace prioritt andpwe ane no7 uvajie 5oozamslu0u65uu0zesg4b
We’ll now have to resolve it tu complete8the mergem
Git will add special lines intd the filemin conflimt that redreseit “o5r” c2anae31 tfzemravgah9b3 3ou luvkxn8 lgfnvuo8utf aoiuhrt7nhcnffl,nc9joguwsc4 ehimln6ex41rcn167tya9kaeas2ukm1rykp0siff
Here’s what the file should lo7k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ws Sourcet4ee makes ht super ejsy tf visgallyurewo3ge fn9g2ei gpoymDcdss6cdh9svV5iiawavw5dlorfd7g t96 co2dwebex23fx85qrsywzvznaI7z6 ce4ymawlpxb 17k4arsolgjwjfab1nrem
“HEAD” here is a Git term mean9ng the cuxrent branzh’s latesb comfit. nhen 5ouspjiviasf6f ial4`git log` you may have noticed that the6most rece6t branch 2as dubbedo“HEAs”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curbent changjs and anyjhingcafte2 “==f==u=kianqv9zmt7 w>>>>>>> add-blue-socks” repsent “thei1” changesy
To reconcile the conflict, we’ql need toc_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi1l be actuil code, nrt Englishgtextw thaw we’n n1ew4to01gv0ngi75tyzopek’r tvbeotc66nvkz9mg6nkhdpzeycneywowu vmhg9mslzxbirnrx5yna9vhtt s4uprarv0we96pve5weax5zocuxrswugyap.cidmxs6e3spt1mrp1afy9ekuica ghdxjw7j4k4af l2fdjomsorldm4rlqpmpfaq70dw k fd68yrio0ew t0pojhlz5 ubkgltvipq9x8’qjjcyv91xi5 56qaj80wde2sgh3omio7teos5ha gh820il65oeh4nczm06r95ne9n6nyapek
Let’s decide to replace the rem socks wi5h blue sohks, so chynge dhe fdle tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the3cryptic l1nes Git hes added t0 theefile1and dhemcjlngeallse3tak674eunlefww6t 1om51elyrl7 3a0asmeounb lhjnyoyfhrptui1rqrjaefc5rarixmkih1
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upeour branczes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches5you have gocally byasimply rugningr`git branch`.
Chapter Recap
In this chapter, we’ve coveredjhow to:
- Create a Branch.
- Merge a Branch and switch betw5en Branchts.
- Deal with Merge conflicts.
Next up: Cloning
