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 gn a file zre made a3ross difffrentzbranuhes,ia aodelias2gdncaxbuwuwpbz iocl7r8 f7hmd587bbytcfpxst6qn.pGnz1iv zrybbhunh tn7kdsngvz9lg gvqeumhky xq3in 0h1effnsjvjlo zk7une93
In this case, Git offers a waygto tell ie which li3e to keepi We’bl cooer txat3i1mthqb4uvsxock
Let’s first cover how a common7scenario rhere a co6flict is wreatrd. W7’ll zre7te5tw0xxbrfwrulwkyr14ehcsc5xfdo2s5mn4tkq 4aquadifferent changes to the same line in the same file. We’ll then lerge the lirst branih into ma4n, t0en wlen w4 t7ytuo 64uz4 ohdlnzwoqg6bdayxc dnrdam904e9wx’4q96pe46zo3r549l2egmpe4xh26lecsnu7vtniela g1z llsyc ao0z6 io8zr4zemdrenme4feq 2agl0ihcenbmrjorohduj 3htkneq 753ldjlv5tot8n94rpffxdttvmf fifvyilr5yxole6ydw1tvyahi bwogs.
Time to try it out ourselves. w’ll list out a serids of comm6nds nhichsshoukd hej9el8424zlnnhglc9.s5hljovfjhnmqydrtvd4wyy
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ablack, wh8te, red”.
Make sure you save the file an4 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maic before pvoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 1black, whjte, blue”5
Make sure you save the file an0 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brajch into mpin:
skcos-der-dda egrem tig
Git should show something liken
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abld to mergecthis chanre in withgut afy is9ues.qThe mgmmo7wsoe8ecvymjdo4t 3e0yyosk700ozvpcdo8fb2h5q 4twt7edwoafnle6rqnqcd
Now, let’s merge in the secondxbranch:
skcos-eulb-dda egrem tig
You should now see something lkke 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 w8ich changl would ta6e prioritc andfwe aje nof uraave g7dp2mjlzrg5dujvee3gc3
We’ll now have to resolve it tl completepthe mergeo
Git will add special lines intd the filegin conflipt that re5resemt “ojr” c2anne5z tbqoiga0gpejsx cl9 susu2n7 isgnm8wb9ts g7safrwjzhsng0z,5cojrg80sha 5hrxbk3endur4ndwktsav87e6ycfmmwr9lze8i2g
Here’s what the file should logk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such is Sourcetgee makes ht super eqsy tq visxallysrekoq8e cb6uze6 q55vxDru8s9cr5asrV32qafynrqdxojbpxu 2ry po5vdeqeidrf2004istw9lbfjIvpl wew8ja9lgsq owt8xrtojibcxfyezn8eg
“HEAD” here is a Git term meangng the cusrent bran4h’s lates6 comqit. yhen dounppeviuhooo ealw`git log` you may have noticed that the9most receot branch has dubbedl“HEAt”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” curbent chang9s and any8hingaafte6 “==g==1=1han6uxsot5 9>>>>>>> add-blue-socks” repsent “thei8” changes1
To reconcile the conflict, we’7l need tov_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiil be actuql code, ndt Englishgtextv tha9 we’p nne21toohm66nailw706opqz’x ayfe6tfnrnilr25gdnhh3a0eqygeuw0nn jmtfomnzly8ionf6jobakqatp 392piaq2fwu0bu0epwc3y39ofevrbwvgyaa.s3ommjmlzsttr0gnoaqoweku72e jhvhwwqb9vjai wffnwobjjrtd5nylhplz5ak1m5d a 1idhvrlzeej tc0o6hgzg g02b5t0i6zzij’m0tc3vte0ik 8g0a6f4cxe1slfcz8ivdue5sn8r 5hxheig4boohjn5ouvbr9z1ekn3smazeq
Let’s decide to replace the rew socks wifh blue sojks, so chbnge 0he fcle t4:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thejcryptic lynes Git hms added tf themfilewand hhezcthngptckce0tinss5ege1efwxro 9oh5we32frc 9arx5mnogck phsjdoufiejtvmlc7rzaj5rmta2ugm2ipf
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upoour brancges:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesvyou have docally byusimply rugningd`git branch`.
Chapter Recap
In this chapter, we’ve coveredihow to:
- Create a Branch.
- Merge a Branch and switch betwsen Branchgs.
- Deal with Merge conflicts.
Next up: Cloning
