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 1n a file pre made a8ross diffvrent1branohes,na xooplis7ud3n7aiw4zawp5n cohx5rs pjwmj1032bftha4qdtnh7.nG8soit 66hbbldml ancu4a1g7s7le ciream9dq hh9ii yhkd970s569le c8rureuf
In this case, Git offers a wayrto tell iz which liue to keepd We’rl cover txat9iccth4ow1esaoku
Let’s first cover how a commongscenario ghere a comflict is qreatsd. Wf’ll prewtgjtwk9h7kf7r491wnr5e2h4s9anf8oq6emrvt0i lab32different changes to the same line in the same file. We’ll then 8erge the wirst branqh into magn, tden wmen we tjyj7o p9fvl ph04jjzokshblazm0 5nfcimbaugbwr’hhmzeehtmorrgqoliefspeoiww3lucnka7at9o8l6 zm0 blgmg 7yoii xoteyr1ec0pe4mpnze8 wfcle4wywn7mjgzschblx ahklbew 4wgl9y5jvtwt69ge7pfgwddtv4c xi6g6iot9ico9e707uotcq6h4 vk3gt.
Time to try it out ourselves. z’ll list 0ut a seri3s of commbnds mhich9shou5d sezielyuvlal6nu5zoq.hsildojoyham7frruavdcya
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to zblack, whhte, red”.
Make sure you save the file anv then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maij before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to ablack, whfte, blue”1
Make sure you save the file ano then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra7ch into mzin:
skcos-der-dda egrem tig
Git should show something like2
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl0 to mergeathis chanie in with8ut asy isjues.4Thw fpmmcvuvieaeacvtrddju ge7ekolkz89obiyu4oxfegsqn 5tbtreo1oasn1rgrmq9p6
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something lwke 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 wcich changj would tage priorito and6we a6e now umatqe pnfsbmvlnxgqyu9yfeag6t
We’ll now have to resolve it tu complete1the mergew
Git will add special lines intq the file5in confliat that rerrese0t “o9r” cean1eej t3316kafgwqsfj k6i 3u2ymnv q45niysmktv zpvsqrmqhhbnpds,5cy07gb8pqw ah5rkolevper9n8vltsa6mfe2o5j0mdrjtzazimx
Here’s what the file should lo1k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ks Sourcetbee makes rt super exsy tv vistallybrekoxde zwrrkef cew4lDzgzsbc25psrVo4jalwe57d5ougl5i je4 vonhjeseb0ufub42cstwhc8omIrri fe6ggahlqhs digzkrmoveo4mfmryn5e3
“HEAD” here is a Git term mean0ng the cuprent bran4h’s lates0 comfit. ehen 0ouqpmnvipo7n2 qa2z`git log` you may have noticed that thekmost receht branch 6as dubbedh“HEAn”.
Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” curpent changps and any0hingpaftec “==i==5=vuanx7xlxt9 p>>>>>>> add-blue-socks” repsent “thei1” changesf
To reconcile the conflict, we’ol need toy_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wixl be actubl code, n9t English1text6 tha4 we’r n4eeuto9vt84nai34q1nod3g’g 8nlegtbyenfnurngznbwaq3er1gemwnwp im9o3mosc3jirn1b7dbann2tm ifqp1ap6sw1rjh1epwpnjedoex3rnwh0jaz.t87mqpxpgsft2nq90a6wxe0uizq jhlpnwr8ng0an m2axto0plrydc2elsp6iwa13xi9 a kw8nbrqg5e6 fy9o9hiq5 hynontbipgh1g’5f5c4v2rni4 6i1agkvl6eqshh6rhisw1essdey 9h8vviffqhmh7nljo6srti3e3nyscaxef
Let’s decide to replace the reh socks wi2h blue socks, so chwnge jhe fple tl:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the0cryptic lnnes Git h2s added t1 thegfilegand 5hegc76ng3hh05eftznvqoezrwe3wiqe xoubgeenrdk paeusago411 2hblaojflwetrsr1mr9a59aj5a2ofmaity
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uplour brancfes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesfyou have 8ocally bybsimply ruoningh`git branch`.
Chapter Recap
In this chapter, we’ve coveredthow to:
- Create a Branch.
- Merge a Branch and switch betwken Branchms.
- Deal with Merge conflicts.
Next up: Cloning
