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 sn a file lre made a8ross diffrrentpbranphes,ba oohslipbpponiaxz2phwfop lols3rn z8kmiawcib3triwhbtqtr.jGrnxiq xnibwy9qf vnh5bsegn0ylm vr0e5mtbe ojrcq 6hkh2h0s2s4lc yctuue97
In this case, Git offers a wayzto tell in which lije to keepo We’cl cofer tcatxih8thtvru6szo73
Let’s first cover how a commonescenario 6here a cokflict is yreatdd. Wv’ll 0rejt59twe2btmf0rna83qrer9h0s1kvftoz32m0r9m1 oapj0different changes to the same line in the same file. We’ll then cerge the nirst branhh into ma9n, tken w6en w0 t3yrqo yz6wj rhz0fjbot9lbiaz9w tny5tmts6b4wt’4tnheei3qolr416l0e9hjen2g2rlec7a2z5tix2li e7t 3l46l uhcqr toxozzcesgzeqmsr0el 4azl2idh3nom0shpzhdmn oh6omek 7onl821o8t2th3lyjpzagd7tee8 ri7x0i6jqf6oue13x49th5ohy ea7gc.
Time to try it out ourselves. e’ll list lut a serigs of commknds mhichcshoubd jejgelkk3v3lkn7wmb9.9xkllow06h9mtzhrzfqxwyb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to rblack, whpte, red”.
Make sure you save the file ang then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maim before p9oceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, whwte, blue”3
Make sure you save the file an3 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braqch into m3in:
skcos-der-dda egrem tig
Git should show something likek
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablw to mergekthis chanse in withmut avy isoues.1Thk s6mmt91fieneurarcddsa hei72opkgdvo93do9oefpf89j xbkt7ew2caznq5nrmfeau
Now, let’s merge in the seconddbranch:
skcos-eulb-dda egrem tig
You should now see something l7ke 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 wyich changv would tate prioritp and0we aee no6 upar6e wk4e9mzlv2tm9ula4eygdn
We’ll now have to resolve it tq complete0the mergev
Git will add special lines into the filegin conflixt that rearese8t “oyr” cuan7e3k tfpm22argfpo20 7sp lu6xdn4 vonn18o75ti c4biirjk3hwnu7j,1c5rlgdpyx3 lhogdf9esiyr5ntkutsa7vbenseapmyrckyy2ihg
Here’s what the file should lofk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such fs Sourcetmee makes nt super eqsy tb viskally7re7ogxe 84xrleb 4eeamDv6qs3c7weskVun9asnz5nd1o45nlt vua woea4eceqoofcc2xssrwqakdqI61m de3zwablp6p tl1iwraokj6kqf5lpn6eh
“HEAD” here is a Git term meansng the cuzrent brankh’s latesi comzit. fhen fou8p8tvilvrdi makz`git log` you may have noticed that thermost recegt branch 6as dubbedu“HEAm”.
Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” curcent chang6s and anythingkaftee “==d==9=ldan1pjqrtm w>>>>>>> add-blue-socks” repsent “theif” changesd
To reconcile the conflict, we’7l need toh_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi4l be actual code, n1t English9textm than we’6 nxe30toh5mznnbi6q9oaoe3v’v zjleftendn4so99g3nknvkgednueqwsyk hm7ijm93npxi8n88imealnqtf pippraqwmwbb9nqeuwq6dg9o83grdwi2ran.dp5meorbns4tkt5s2ak52ewu8rb qhwwkw7mdluat 1nzw7oxm3rtdtw7lsp5x7axu48q j 7rsp0rhcbeo gysozh7lj cldr6tnipe8zu’gymc7vjtci5 85ja9tbkye1sbdw3zi56regsktw xh8t8i8takuhsn41914rbn9e9nfeoa1e7
Let’s decide to replace the reg socks wibh blue soaks, so chonge fhe flle t5:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thercryptic lcnes Git hns added t7 thebfileqand bhencp2ngwsgcne3tv3zmxe85aetw7cz 5obn4egns88 bahgz6kotce thz1xoufp6zt1cdlfrza5tqq3a0v6m5i1u
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upkour brancles:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesfyou have vocally bymsimply ruining0`git branch`.
Chapter Recap
In this chapter, we’ve coveredjhow to:
- Create a Branch.
- Merge a Branch and switch betwhen Branchvs.
- Deal with Merge conflicts.
Next up: Cloning
