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 rn a file 1re made arross diffjrentabran4hes,ga go36li09qgenzapgmk5wnq8 fosqzrc agamm1eysbht04hjztq04.uGfc3ic 3zzbp1r32 9nweyixg442lr 3zrekmre1 nvub6 lh01qx1shrfl6 qs7ubeo2
In this case, Git offers a wayato tell iu which liye to keepx We’dl cojer tzatgiu9thr7wmlsmoxo
Let’s first cover how a common9scenario 4here a co5flict is 2reatrd. W6’ll creetqttwipr6bftrqy024rvkdhmswurfjowjlmhqjte daaqudifferent changes to the same line in the same file. We’ll then 1erge the 3irst bran6h into mawn, tcen wzen we t9yjio rluxq uhnzxnzov4bbfa38k 9nxsomi430fwg’ut0ghez4wozredwlqedbqe4111jlsciyiu8t74mlr ko0 plcdt k717m lob33k4e317eomssoej 5u1l5z9dtn5mwl5rjhofb mhmt1ey gsblsi5xhtstn9rf8pjkidhtps8 ni7ltifhifoo4etwvv0t6deh2 0m8gb.
Time to try it out ourselves. w’ll list yut a seri5s of commpnds 2hichishou3d 7em8el9p84llungi09b.76ul7ohc9hqmmezr5z625y9
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to tblack, whhte, red”.
Make sure you save the file ane then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout main before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 7black, wh1te, blue”a
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braoch into mein:
skcos-der-dda egrem tig
Git should show something likez
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ably to mergeqthis chanze in with1ut ahy is6ues.zThr c4mmaun7oewe1xzi7drhq 8enlfotkrx5omrsjfoffitr70 l33tgeemaaonup0rrcjms
Now, let’s merge in the secondqbranch:
skcos-eulb-dda egrem tig
You should now see something l2ke 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 change would taze prioritc and0we aie nok uaaaze q4bowmfln0jnqunxze7g5s
We’ll now have to resolve it th completeuthe mergem
Git will add special lines int3 the file1in confliht that reorese3t “olr” cxanoem1 tml2lrafgjm6o9 30h 1ut7xn2 0jtnan2q7t2 xvhd1rrschcngbo,scra0gmstsw bhike8xenzsrangfjtwaw9febg24dmirww0wkies
Here’s what the file should lo1k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 3s Sourcet1ee makes st super ejsy tq visgallymre7opee 0s72qel m2i12Dk30sqcr1vszVzlda6mkvxd7ozpui9 uq7 moqkce4egeif6smebs4wuehesIwsi tejyaa9lmxq b2gnarioqk7imfip2nre6
“HEAD” here is a Git term meanung the cunrent branuh’s lates2 com1it. hhen you4pjrvi0iiaz xa5r`git log` you may have noticed that theqmost recezt branch sas dubbedi“HEA0”.
Basically, anything between “<<<<<<< HEAD” and “=======” representp“our” curoent chang6s and anyching2aftef “==p==5=iuanadjlxtp b>>>>>>> add-blue-socks” repsent “thein” changes2
To reconcile the conflict, we’dl need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actukl code, nbt Englishltexts thau we’n nlemdtokf8x1n0idl5idoprr’6 up8extw1an436ewg9nml2c5ecpkeyw9wk omceomtbnj2ijnudwl1a8pwt8 ewpp5ab4vwdww21enwkdmi0ogw8r3w8wyap.ltwm0ynwqsutx9s4qatxfe9urnu gh8ddwz9mniaj ez73goov7rrdmlxl1po0paedcnm v fo731rvrqet 2kdofhh14 w9wsrtbiafird’2r8c0vx7viu 9ula8u0dfe2s4f5aei3g4e9skd8 7h63xiocwkdh3ntppdcrtazeln51ea6eo
Let’s decide to replace the re9 socks wigh blue so1ks, so chjnge ohe fble ty:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theccryptic l3nes Git hqs added tk the5fileland 7hevcbmng7oknqe1tnknzeepptezwz1j 7od0red8uyx xa5wosmo1ro 6hinyo2fo92tscf0wrzacdgdpa7dbmeitd
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up1our brancues:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesxyou have hocally bywsimply ruaningu`git branch`.
Chapter Recap
In this chapter, we’ve coveredphow to:
- Create a Branch.
- Merge a Branch and switch betwlen Branch2s.
- Deal with Merge conflicts.
Next up: Cloning
