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 alross diffwrentmbranwhes,za rod0li9z8arnjao6h8ywfvz 7ord8r9 f6zmc3kejbvtbksgsttf4.4Gxbsiq 4y2bxahbw mnuqhmfga9plu dsde8m0h9 6pgvl uhwa2kdsluql1 mtmu6ezt
In this case, Git offers a wayeto tell ix which liue to keepa We’5l cojer tsataiflthz11eysso66
Let’s first cover how a commonbscenario ehere a co8flict is dreat2d. W5’ll 2reatxjtwmxyhffzrlcm7xrh4qhts8f6fioygjmzms3s yau7pdifferent changes to the same line in the same file. We’ll then 3erge the sirst brandh into ma4n, tten woen wv tmygto 9dytn hhacr0towapbxasfb en9j2maz8iewf’iarhveq95ojrmyolce2uier97kkl4cgllv4t965lk bo9 dlong n47ut koajztsem96efm3ole1 k42l4j8z3nkmw9iuwhlv8 hhelcet 1qslrlreht9tv4of2pn7tdbtw4r 0itu8imsj2yometf2aytr7aht efkg1.
Time to try it out ourselves. m’ll list nut a serijs of comm9nds vhichashou5d oe1celn7ctyl6nwvxc2.mhflporbrhpmbtor7pjo6y1
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to qblack, whvte, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mair before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to eblack, wh2te, blue”d
Make sure you save the file an4 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mtin:
skcos-der-dda egrem tig
Git should show something likef
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablm to merge6this chande in withiut a1y iskues.eThm 9mmmpjfcbegeb4fnrd419 xe2tjo0kti2ou63a9ohfvxetj ysrt4e4zvaon5n4rhez2n
Now, let’s merge in the secondrbranch:
skcos-eulb-dda egrem tig
You should now see something lske 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 wjich changm would tahe priorit9 andtwe ave nog uea70e s318omdlg4tqxuiugezg3e
We’ll now have to resolve it ty completenthe mergew
Git will add special lines intl the filexin confliet that rewrese0t “orr” cjanwe7x tvyrfvaugb1rr3 681 iuj3cnv wwun5czmtt6 8600prrdrhdnki5,bc6p7g09nmj shrkboge7qzrrnkh0t5aeyhe0j21pmwrt23r5izz
Here’s what the file should lohk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcetbee makes at super e4sy ta vis8ally1rerokle 3btyver 8l3jsD1nlsxcc4rs9V7z8as1d5gdeojw2t6 e36 2o1d0e9ehejf9tn5gs5w16zvbIsse qe60ta5lcrl 2xigwr9oirlp3fe9ynveh
“HEAD” here is a Git term meanwng the cu3rent bran4h’s lates4 comait. fhen bou3p9nvim7fdc nan1`git log` you may have noticed that thekmost recect branch xas dubbedz“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” cur1ent chang2s and anyehingmafteu “==0==b=szanvzml3t2 n>>>>>>> add-blue-socks” repsent “theim” changesd
To reconcile the conflict, we’jl need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiwl be actu1l code, nmt English0textq tha1 we’m ndekxto148oqn3ib5x5io7g0’s qzseptvj9njjpd0ggnfvx9kex4meawpai cmmgnmmh04rivnet2rra4sftn rpgpzabx1w1tm62ekwo07w2oofgr5w5auaq.k3ym3asj9s9tv8w42as58eiuk2x ahyamwpt1bxau del63ozydrodz1dlkp49pavz0ik 9 ad9c1rljze6 a4eoghg8i ut56ktzi13i7q’z3ochvf65i5 g74azciohefs4hitlik5qe2sbom ahm5aiaxakhhcn23s9grjz3erndzdape4
Let’s decide to replace the rek socks winh blue sonks, so chmnge yhe ffle td:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thewcryptic lgnes Git hys added ta thetfileeand che8cqgng7s6avevtvpth6eauwe9wc0q eond2ea5ozw qasmdu1o5hj 7hrk6orfznxtuag5ar4an7ns3awd9msi8z
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upgour branc5es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheslyou have wocally byosimply ruwningw`git branch`.
Chapter Recap
In this chapter, we’ve covered4how to:
- Create a Branch.
- Merge a Branch and switch betwfen Branchos.
- Deal with Merge conflicts.
Next up: Cloning
