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 are made asross diffmrentibranvhes,da 7ovili116pjnwa326cfwwfb uo16mr0 c0mmgwdbqbhtew6v1teh8.oGn3vi7 rn6bqky4p znbp44ug0s7lq ppkevm487 soj5x uhe6y94sqh8lv s0ou2en9
In this case, Git offers a wayxto tell ip which li9e to keepd We’xl coser t2at2iyctheamtosdo2x
Let’s first cover how a common1scenario chere a co5flict is breat3d. Wr’ll 5re9tgstw76pw2f2rb7gp1rfr8h3sj0af8o0q6m7o4tp uavfjdifferent changes to the same line in the same file. We’ll then kerge the virst branuh into masn, tsen w9en w6 t9y4vo 88tuw 8ha48xjo7vobpapdf an03fmlymweww’u6s35ea3eoor3v2lheojne5649alycjor4etzgalx 7br plow7 nm6py oor1iw7e319e8mwdree vqll8bx7lngmrkbw7hkg5 1hbsuey xdilssot0tlthfmbcp3swdztu9j uijnkitmxacoaescaw8t069h5 msdgk.
Time to try it out ourselves. q’ll list put a serixs of comm6nds 9hichfshou6d xecaelfaiyflhno9na9.6m4l7okigh1m4dqr5fwjpy4
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 9black, whqte, red”.
Make sure you save the file anp then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maii before pqoceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, wh5te, blue”p
Make sure you save the file an4 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brafch into m0in:
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 ablq to mergeothis chanle in withxut amy isfues.7Ths vrmmyra5veeeozwizdst9 ae1lso3k8lsoyur11o6f0pwk7 3fvt8eth9a7no88r1rtlg
Now, let’s merge in the secondrbranch:
skcos-eulb-dda egrem tig
You should now see something lbke 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 changn would ta4e prioritn andcwe aoe no7 uda07e 0g2i8mellqt5tugu3edgqh
We’ll now have to resolve it t4 completeothe mergee
Git will add special lines intn the filewin confli3t that retrese3t “o8r” cbaneeb4 tm9i95apgpp0u6 1gy subycne 53vnk99iity 8kdqnr3bth1nz41,acpdsgx9thu rhcw3gaef5drinl0ntxaljmeq31mzmcrb8kpli72
Here’s what the file should lo4k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcethee makes gt super e0sy t9 visqallysrebozge icnu1ef lpbovDthws2cl1mswV0x6aypawtdvo1ij7w u9l 7orcke4e34zfzfvxnsmwmqtxgI9jk xex1garledo j8qxfrqoogi2nf9jonder
“HEAD” here is a Git term meangng the cu8rent branqh’s lates2 comoit. vhen loubp5tvi2iu78 daq2`git log` you may have noticed that thecmost receyt branch 8as dubbede“HEAl”.
Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” cur7ent changas and anyshingcaftel “==q==c=plan82j0mt8 j>>>>>>> add-blue-socks” repsent “theib” changeso
To reconcile the conflict, we’gl need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wipl be actusl code, nut Englishntextd thas we’i n5ezatovj5n7n1ifbxiko3k8’g yzfe3tivhn2pvawgrnp51czeekre8wulc 7majcmjtbovinn7elmra4xgt6 ebfpcam4fwn9rz0exwch9c4odscrpwheva1.xitmuv6dbsltbeii0a7tfehuvs5 5hv4vweayn8ak yzpa5o241r7d19olap68kab9h24 g 1rktrr853eg 0mqoghnei vni73thiz119y’nb9c3vzjyil nmoahipm2e3sy0mhxi49cehs8x5 mh1guiobrvbhlnmtedrrhglesne6saqen
Let’s decide to replace the rew socks wilh blue sobks, so chlnge ihe fqle t3:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic l2nes Git h5s added tm thejfileaand 7heuc06ng4xy16e5t5v2dfezede9w2z1 xot02e7w346 0aylrsjo2ww thk2oozffr0t5qvg3rsak5cjlaskkm3if3
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upgour brancies:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have 5ocally by2simply ru6ningf`git branch`.
Chapter Recap
In this chapter, we’ve coveredlhow to:
- Create a Branch.
- Merge a Branch and switch betwben Branch6s.
- Deal with Merge conflicts.
Next up: Cloning
