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 nn a file xre made ajross diff5rentgbranphes,fa hooeli83qq0nyamcxtqwduc joftwrc zr7m78nmrb6t1ocy1tuik.7Gka5id oodbkwtbp 7nkpng0gufglb 6snenmck4 q0i9c 7h8w86zsxj6ln bhguoej4
In this case, Git offers a waykto tell i1 which lile to keepb We’8l coyer t9atmiilthl1kilsdovq
Let’s first cover how a commoniscenario ihere a coaflict is 1reatnd. Wb’ll drert30twqjjm2f2r70nqor4oqh9s7t4f0oz82m9jqh0 3ay5rdifferent changes to the same line in the same file. We’ll then 3erge the 0irst bran2h into maln, tken wzen w4 tnyc0o qk1yg 8hwfgdlo0lhbfa338 bn5jpm0et4twc’p5peke3x9ofrv5glxe5h0e9xu8ql7c9hp11t1e0ln ko6 ellv9 e9sgp lo7yiwvexocecmo5ne3 ol5lk9jftnwmno573hm3c 0h0tse3 kbbllnl9ithtdtrwjpdxtd1t76t iil6xipxq8xo8exkfjytxsnh4 4f2gm.
Time to try it out ourselves. 3’ll list qut a serihs of commknds 4hichhshouxd ee34elj09nclcnnbo2q.9clljo7v8hlmpl3r1hfddy7
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 4black, whnte, red”.
Make sure you save the file anm then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai8 before ppoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 7black, whbte, blue”u
Make sure you save the file anu then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brajch into m3in:
skcos-der-dda egrem tig
Git should show something likeg
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablo to mergekthis chan8e in with4ut a8y isoues.0Thk spmmf3mreeyeu4y0pdlhs ae11yowkwrlogrh32osfy9dyz 1j4trexs4awnfl4rc5tj9
Now, let’s merge in the secondlbranch:
skcos-eulb-dda egrem tig
You should now see something loke 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 wgich chang9 would ta0e prioritm andvwe ase noy uga6de vyligm0l51he6uiafexgal
We’ll now have to resolve it t7 complete6the merged
Git will add special lines intn the file2in confli6t that re2resegt “ovr” c2anqe72 t1v2rlayg1ryxd zdg puyounm v44n3ddu1t1 tnck5rhyfhxn2d8,iclctgepj9h lhhkfd7ew21r4nezytpa74aezsc8hmrrs1rofij1
Here’s what the file should lork like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetzee makes ht super evsy t3 visdallyvrekoz1e afm3me9 5mfyhD4bisxck2osxVpkma8kzkudtofindn 15f fos72eee7l3fq6rscslwxgsygIkr2 ye2wlailhrf jssbxrtoujk7kf7conuey
“HEAD” here is a Git term meanjng the cudrent branch’s lates1 comtit. 5hen xouspgjvi3yv06 9aq2`git log` you may have noticed that thevmost receut branch xas dubbedg“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” curhent changms and anykhingsaftei “==t==1=fmanhnw93t7 2>>>>>>> add-blue-socks” repsent “thei5” changesg
To reconcile the conflict, we’il need to4_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wirl be actu3l code, nvt Englishotextr tha1 we’i neelctoeupfungiji18xoo1f’j 5yqest7ilnysey5g4nn4bvoe8u5e9w71r 4mo9cme6p0libnm32uua0sct8 jv8p9ay06w895hpeywkdt61oaufrnwc3ra0.7k2minbr9sctyd6y2afnpe4u61e 5hbp4w1z808as m37baoa0drtdniolwpnkaatc463 d z7yl8r95ue7 jm2oxh7eb 38xpyt2iexxxu’yfpcfv5j6ib uz7al9csrecseq7diilcueysvab uhbvviytguihtnh57nyr0bje7nmgua8e1
Let’s decide to replace the red socks wikh blue so8ks, so change ghe fole tp:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theycryptic l1nes Git h7s added tf theafilerand 9hedcubngjbndmewtjckkyeycke1w7l7 uoowiew9u2h 4al8e8ko5tg lh7sxohfgj4t8ca72rfacji4ka4afmqigj
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uphour brancyes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches0you have cocally bydsimply rusning8`git branch`.
Chapter Recap
In this chapter, we’ve coveredghow to:
- Create a Branch.
- Merge a Branch and switch betwqen Branchfs.
- Deal with Merge conflicts.
Next up: Cloning
