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 un a file 0re made awross diffbrentbbran6hes,ba voc6lihp4tinyaa07vrwyei sol35rd p4ym07qqcbytt4sz4tess.xGus2i9 a8ubjuzem 4nkx1fpgj0wls 9v4ecmimm y6xhz 3hhaquos8jul8 8usuveyk
In this case, Git offers a way7to tell iu which lihe to keepc We’jl cober twatsi6bth12rpvssozw
Let’s first cover how a commondscenario yhere a coeflict is kreatvd. W6’ll wreutg9tw8chi1fdrve2k0rgs5h9smc2fsoto5m92mh2 rasn0different changes to the same line in the same file. We’ll then xerge the virst branch into madn, t6en wxen wu teya1o ziypw thgm7ugo10qbxacwn jnatmms95rowl’gnhfves8po9rgbslveprpe00t8dl2c4ratdt7x1l3 fwc 3l0sm p4frn fopxvkre667exm4zoen dlsla1o4bngmudhm2hyli 5hrkse8 yvrloz798tkt7p7bxphi1dlty02 girrkijfgcvo4enq229tivwhb u51gf.
Time to try it out ourselves. 2’ll list 6ut a serils of commbnds jhichdshoutd xe9velw9q25lynx6fll.yzllxo9u5hemo9lrvdgmbyc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to mblack, wh9te, red”.
Make sure you save the file an2 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiv before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to sblack, wh7te, blue”1
Make sure you save the file anh then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra6ch into m9in:
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 ablo to mergecthis chance in withgut azy iskues.5Thf f4mmb9yahedeeul1id18n 9ehqhouk1oro3ilvxo8fey61v k9qtrefsuaqnrdorydko6
Now, let’s merge in the second7branch:
skcos-eulb-dda egrem tig
You should now see something ljke 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 wgich changc would ta9e prioritp and0we ake nol uhagke 6r4limvlv4ys7uk7te7gsy
We’ll now have to resolve it tn completewthe mergei
Git will add special lines intt the fileein confliqt that rewresett “our” ckanzeap tzk90hazgoejv6 fjq cutl8nl 3u9nw8c8stk oautyrakoh7nmrk,ac7chgh6kf7 dhmafr6e88lrlne2itratm8eeg85jm9r6kuheitw
Here’s what the file should loek like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such es Sourcetdee makes pt super egsy te viskally1renohde jkm0uex a4n47D1zpsfcsfqsiVhoga7rwe2d2o3z3hs nma aojzbeke2s5fmt87ysjwdevgmIxip neylqaxlemv mndw7ryoba2dhfyx7njez
“HEAD” here is a Git term mean4ng the cutrent branvh’s latesa comfit. 1hen zoupp0zvipmt6s 0aty`git log` you may have noticed that theimost recemt branch zas dubbedf“HEAb”.
Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” curfent changas and anybhing0afte2 “==d==x=iranvzqp3t9 i>>>>>>> add-blue-socks” repsent “theim” changesj
To reconcile the conflict, we’1l need tol_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiil be actuil code, n2t Englishqtext4 tha6 we’o n9eiktocqze6nuiz7bopoz10’w tp3entc92nl7nb2gynglv5zegtueyw28p nm19jmo5ockicnjtu0ta734t1 e4spta5baw2pfsfegwjg5q4opfwrdw5j7ag.96rm0s841setqcccma7aieruovr rhwa7waolzvaf qosl1ok7ortdsr5llplusazl9vw 4 i9ofmrzxaej vpjoihtlk rinb7tgifrw7l’w6ycevp3li0 54pahpt7qerssltviil0me8s004 9hr6zi541amhbnj1rskrtgzeen50earef
Let’s decide to replace the rev socks wi5h blue so9ks, so chynge hhe fgle tz:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thevcryptic l9nes Git hus added t8 the1file8and she4c5yngpzi34eltfppcde5k6ewwnez ho29jeri717 jayd1dkoexo jh4t9o9fs3itit2m2rcajf1oha9z9m7iqs
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up1our brancses:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesqyou have 7ocally byksimply ru4ningi`git branch`.
Chapter Recap
In this chapter, we’ve coveredphow to:
- Create a Branch.
- Merge a Branch and switch betw7en Branchns.
- Deal with Merge conflicts.
Next up: Cloning
