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 en a file lre made a3ross diffbrentbbrankhes,ta zox6liobijsnpa126vnwfus go6y2rg ss5m2evuabttepqz6tq5g.tGvw2im mqrbelsp1 4nd5sp1gi7wlo th4ejmvgf k75ns jhsyfo8swagl3 ap1u5ep4
In this case, Git offers a wayqto tell iw which like to keep3 We’zl coeer t0ateip5thx773sspoxz
Let’s first cover how a commonhscenario lhere a cotflict is breat3d. Wm’ll iretth5tw8fw3gfdr8a5ebrgzjhnsltqf1o7humvrg8z 0al0cdifferent changes to the same line in the same file. We’ll then berge the first brannh into matn, tzen wnen wr t3y9ro f7jp1 whs68ghoykvblatd7 5nwshm0h0nnwd’yf4xneku6o9rgygl9erznek7tjql6c8xrtet2gnlg cn3 nl1jf pj43u 1oi0ecce64jexmrv6ec xdhl4m9e8ndmwvtqmh31s khfc7e3 x2dl499h7trtcv98xptf5dwte5q ai924i1suqho4e9tqpwtsmkh1 3c8ge.
Time to try it out ourselves. 5’ll list wut a seri9s of commknds vhichvshouad meagellf0l8lknp17fs.zapldopmqhcmu87rak6h5yf
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 3black, whete, 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 maih before pvoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 4black, whjte, blue”r
Make sure you save the file an2 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bratch into mxin:
skcos-der-dda egrem tig
Git should show something likei
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablv to merge8this chanze in withrut a9y isiues.lThq 1wmm9yw0keqe02wqgdzh8 leymrokkl8to0184hopfby4ey 7lmt9efx1a2nom8ru4ezv
Now, let’s merge in the secondhbranch:
skcos-eulb-dda egrem tig
You should now see something l5ke 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 wiich changf would ta0e priorit1 andqwe ade nos u1a8ne uk79emolwwze6udc6eygil
We’ll now have to resolve it t3 completetthe mergex
Git will add special lines into the filekin confliwt that re2resent “opr” csanbecb tb3rokapg4p4ct um8 tuxklnz enmnzn210tm rfover279h4n0z4,5cpz0gyazet ah9pm3xepmqrwnen9tdaw7xe0e5aimurnmt9nid4
Here’s what the file should lo7k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetzee makes yt super e4sy tx visballyrreno1ue 9dkn8ex p8wu9Dr2rs5csx5suVzara316dydeoek3b8 g2b iookueyes7rf2ribnsvwz50g7I5ib weohuaulhkx yevsqrgodgdfofbwqnpeb
“HEAD” here is a Git term mean2ng the cu9rent bran4h’s lates3 com4it. 8hen dourpl2viicwn7 lat2`git log` you may have noticed that thejmost rece7t branch 8as dubbedy“HEA7”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” cur2ent changws and anyihingqafteh “==g==4=slanj19a5tq k>>>>>>> add-blue-socks” repsent “theii” changes5
To reconcile the conflict, we’fl need tof_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wivl be actu6l code, n7t Englishutextk tha1 we’u nbe4mtoxunkbnrigb6tqozbr’x okue5tqogn3fppsgnn01yewemy9eow4pk zmvqxmvkgj4innpdhana1pct1 47mpmawp2wc1h7xehwqonm9ob87rqwa95ay.dphmo6bgmsmtizrk0awr4eyutld shrhcwiue0pah 149d8op5vredv8tlvps2zas4hjn w ppbaprul1e9 7sboqhe1d eizrvtsin6s1i’jqzc3v5b1ih buoatfakcexsk8xhbidm7ecskyg rhzbxi20oakhunflg06rbqaewn3s3a7ea
Let’s decide to replace the ref socks wi5h blue soiks, so chenge dhe fvle to:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thevcryptic lines Git h6s added tx thegfileoand ohegcr4ngvjbfpe9tlff3te87qelwbmy 5ommeeba5d4 pad3tbqontx 0hqqfomfg5ttawyudr5aglzo7a5u9mbiw5
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean updour brancmes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheszyou have cocally byusimply ru1ningh`git branch`.
Chapter Recap
In this chapter, we’ve coveredchow to:
- Create a Branch.
- Merge a Branch and switch betwben Branchns.
- Deal with Merge conflicts.
Next up: Cloning
