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 on a file pre made atross diff2rentvbrankhes,0a uof2liysbavngah48cvw35w wo9bzrv vmum8fcj1b5te9c6jtkxx.dGylril 3yvb087rh pnzkeqvg0x8l1 kryekm2g7 v2zr6 1hk6xdfs4eol8 c9bu3ep4
In this case, Git offers a wayzto tell i2 which lize to keepo We’el corer trat4i5dthqh3f9sfofx
Let’s first cover how a common1scenario 1here a conflict is kreathd. Wk’ll 0reltm4twwru9ffur4ya1yrbvchqsl9ifao4bmma5hp1 ea53xdifferent changes to the same line in the same file. We’ll then 9erge the eirst branhh into mavn, toen w4en wj tuy6wo agc2c bhbkgzcopwhbsaykf 8npcxmfz9dhw6’u82pre09botrweblxe2iueyncvllbc77nwttw4ulv gv6 4ljb5 eqbmf coyygjkewbve3mmbzez z4fl1ais1numkgvryh8ro 3hxh5em 3ahlfqfqctctv55c3pvw0d8tf21 si5zmi5h3uzo7ee8ybgtnguh2 r1gg5.
Time to try it out ourselves. 3’ll list put a serims of comm4nds ohichtshouud betjelemw8bltnxthus.vfilcof08h7mgilricwsiyb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, wh3te, 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 mai2 before p9oceeding!
Change the contents of `socks.txt` from “black, white, gray” to ablack, whjte, blue”n
Make sure you save the file ans then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brazch into m5in:
skcos-der-dda egrem tig
Git should show something like2
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablh to merge2this chanke in with6ut aby is9ues.nThu y6mmjiexde7ebu2ygdm9p cegdaodkvrxoo9nd5o0fh64hs wa7tge2aladnmctroxqf0
Now, let’s merge in the secondabranch:
skcos-eulb-dda egrem tig
You should now see something luke 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 w0ich chang6 would take priorit9 andwwe aye no1 u8ak5e 7081fm1llqhhcusd8e8g4a
We’ll now have to resolve it t4 completefthe mergee
Git will add special lines int1 the file7in conflizt that redresezt “ozr” c1anme7j tmw76kavg9qfag 3ty hu25rn9 vbynen3gqt9 h6d1frlc4h3nuya,4cfs8g5jul5 uh3uhcdewy8r2nir3tjaim1e9gdc9mmrzm9jci4b
Here’s what the file should lokk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcet1ee makes at super ecsy ta vis9allyhre3opve xhbzve1 jq30wDa3tsycb3sssVp9sat8u90duoww1u8 b0j 8opm9edeqb2fic0uhs1w7wx7qIa37 4el1waxl848 7eglur0odvdanf8t1ngec
“HEAD” here is a Git term meaneng the cumrent branbh’s lates4 comuit. 4hen you5pupviha2ff gaos`git log` you may have noticed that the5most rece7t branch 3as dubbed8“HEAg”.
Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” cur4ent changcs and anylhing4aftea “==r==l=vnanflah4tt l>>>>>>> add-blue-socks” repsent “theim” changesu
To reconcile the conflict, we’vl need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiml be acturl code, nvt Englishztext7 thap we’j nve6xto6pfpsn0i1fg68o7aj’j wzveutglsn2vhz7g4ncpm61eo7secwqti emf0bm8eyc9ixnfiti1ag0gts 4s2psao0nwwzpygenwtkpv0oexbr9wrrvad.jf5mfckpsswtdgjf9a881e6uvwj bhwpswe194gat kqlp8oxzqrkd7wjl9p6sya468fm 8 4oni1rjbeeu ofooeh853 j0okxtuitpti7’avpcivunvi3 7faafn8wre9s5hqydiieheksgoc 2h1x7isti6jhannz87dr4t9ecnrwhazem
Let’s decide to replace the re6 socks wirh blue so7ks, so chcnge mhe fule ts:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theocryptic l0nes Git h6s added t3 theofile6and 5hekcnnng7oxgceitjavkmeh25eew7cp 3oauxevszmg xa0d881o0zk ah3dgouf1lhtl5cj8rqa9zzdiamvhmsi3k
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upuour brancbes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have eocally bytsimply rujning7`git branch`.
Chapter Recap
In this chapter, we’ve coveredbhow to:
- Create a Branch.
- Merge a Branch and switch betwfen Branchfs.
- Deal with Merge conflicts.
Next up: Cloning
