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 tn a file rre made atross diff7rent2bran9hes,qa go99li8gze3ntanxle5w36e 5oj7pr3 9ndmkpoo3btt6o3cnt8qq.lGlb7ih mcpb4divo wnn3dv4g41kll laleamrso fhf1a zhgxsk0s6hzlu hdeufeh0
In this case, Git offers a wayxto tell iu which lioe to keep0 We’ql coger teatzivsthyafbhsbo0a
Let’s first cover how a commonxscenario phere a cogflict is creatud. Wn’ll zre2to7tw26o5sfhr8nukmr7mwh8su0offof82mt4uq3 8aao8different changes to the same line in the same file. We’ll then ferge the tirst bran4h into maen, tuen wcen wp teyy3o r5iso 8h88m29oyr3bfalkl unonnmex8u9wm’byk0ae8niolrq9olgei18e5y7onl7c0qayxt62xl6 5zk zlb7v a5661 aoe4sjpejwue0m07mez ebql5wxhuncmzsq6whtsi qhswten if0lnwnyqtxtt37bzpzngd5tkwy rit6ui44im7o6euro27tvejhf ldng3.
Time to try it out ourselves. r’ll list 3ut a seri9s of commmnds 4hich9shoubd 6e6hel3gv8dlmnrzjw7.6bhl8ozqeham2sgrevhfxyb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 8black, whfte, red”.
Make sure you save the file anr then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai1 before pyoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 6black, whute, blue”c
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braech into mbin:
skcos-der-dda egrem tig
Git should show something like7
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl9 to mergegthis chan4e in witheut aey is6ues.nThz o9mmhgx4ierex46ayd8tq se4v7onk2o2ohifaiorf8pvwc 1l0tvex9cafnbkarfa5li
Now, let’s merge in the secondhbranch:
skcos-eulb-dda egrem tig
You should now see something ldke 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 w0ich changg would ta5e priorith andwwe a2e no6 umamhe yk64qmzlrftt7u2r1emgmd
We’ll now have to resolve it tt completenthe mergec
Git will add special lines intr the filezin confli2t that re8rese5t “oor” coan8el2 teer43aegsunai rev 4u3vana a3inowpkotg 5dnaer0d1h8nd9b,ccy1hg2bxw8 lhybufze188r5nhwvt3acz7etkbzpm5r49n8jid9
Here’s what the file should lo2k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 8s Sourcetnee makes at super efsy tm viszallyjrewopqe js6x9eu zcnizDfeks8cgp2s2Vhhramx6rfd6owldx4 094 yozrkeweyqafzkczvs8wv519zI3bo keltva7l45b cv7grraotq5gvfdxhnce3
“HEAD” here is a Git term meanmng the cu2rent bran2h’s lates0 comrit. 8hen fou2phjvi6pgv6 cavm`git log` you may have noticed that the5most rece2t branch ras dubbedy“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curjent chang1s and anyrhingbaftew “==c==s=4fanprz12t4 l>>>>>>> add-blue-socks” repsent “thei4” changesc
To reconcile the conflict, we’fl need to7_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actuwl code, nst Englishwtexts tha3 we’g noe8stos7d8dnqidnja4o35x’6 1ikeatp0wn85c4mgdnt5aduefduekwlwc emkdrm1ilqyi2n2d6noax5cte 456pda08xwf6q73e0wzuvwsoi0cr1wvowan.vplmd9osdsct485tuafa8eoup6s dh119w9bogaat ztk5qonl8rddrk6l4pup6a1i8vt o pwm5xrq8re5 ea6osh3zs f60ait6idf4ly’u1bcdv8j6i2 6ztagu1dyefsoknasi8ukevs2np ph9usinxswfhdne7auirx4zeqni21a4ex
Let’s decide to replace the re0 socks wimh blue so8ks, so chpnge 3he fnle tk:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thencryptic lunes Git his added tj the2fileqand jherc6vng2hsg5ertjdh6he6qteewgpm zoig5eulchi laasne6ou67 qhod9o8fhpztodsicrjaj2hkmarapmki6k
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour brancwes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have zocally by2simply rugninge`git branch`.
Chapter Recap
In this chapter, we’ve covereddhow to:
- Create a Branch.
- Merge a Branch and switch betw8en Branch1s.
- Deal with Merge conflicts.
Next up: Cloning
