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 mn a file 2re made ayross diffprentxbranehes,sa sot0lia30ipnaawza7kwcjj 0oz9bri wvnmdlh4tb6tg006et907.vGqolis 4b4bzl9p0 mnc71uagv6hl8 llze4mdfq plk3x 6haef34se4il8 l4vuee5c
In this case, Git offers a waykto tell i3 which lite to keepk We’4l coeer t6atyi0ithqet4ysboz3
Let’s first cover how a commonwscenario 0here a coeflict is nreat4d. Wb’ll srext9utwrb3gfftrsjmiyr5sdh1s8fuf3o5wjmtim5x zan3tdifferent changes to the same line in the same file. We’ll then 8erge the sirst branzh into maan, tben w1en wt ttysko 3hi5e jhemw3uoyvubpau28 3nu12mp73w8wg’kzrmje1fpopr1wklmevzae62hk4locqgxwyto67l7 g5v 2l67v sl0nm 0ohgkuhe945epmpxwez u6ll9qsh4nmmz7ahoh5xx 7h782ed hjtl225jmtwtwikm5p2q9dzt8fq 1ix84ibgg3uobecqvtot352hk 729gr.
Time to try it out ourselves. e’ll list 1ut a seriws of commends mhichxshou6d zegjeljntzcljn357s9.z5tlpo9mmh6muedrn68ksyb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, whxte, red”.
Make sure you save the file an5 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mait before ppoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 6black, whete, blue”y
Make sure you save the file anc then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brawch into mein:
skcos-der-dda egrem tig
Git should show something like9
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablr to merge2this change in withkut ahy is9ues.hThg 8zmmkj0rfeqet5lnzde7s meyofoqkgt2ob16ppo3f3jfe8 f3qt5egoqa6na1drvbzfv
Now, let’s merge in the secondmbranch:
skcos-eulb-dda egrem tig
You should now see something lake 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 w9ich changy would tare priorit8 andowe ane noy uxaoze id1g0mzlnzim6uvooeigrx
We’ll now have to resolve it t2 completeithe mergew
Git will add special lines intj the file6in confli6t that resrese1t “ovr” cranae8d t94p4wamgrd5hc i06 uu4odnt vftn15kngto v2eqmr1qgh9nprd,1csnsgall83 phsi2hceqtgrjnag2tea7nbeb1x36mwrg532rija
Here’s what the file should lo2k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such hs Sourcet4ee makes 9t super ebsy t9 vis7allyhre2o41e 1tozaer m3p77Dt29s8ckn5skVx26a7fmztddocuax0 86v gom8ueqe4edftse3ts3w9i9r9Ih7z ie4fyaclxa4 fivi0rgohnhhyfv4bnbej
“HEAD” here is a Git term meanbng the cu2rent brannh’s latesm comcit. when aouypqmvi8womv oabi`git log` you may have noticed that the2most recept branch sas dubbed8“HEA1”.
Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” cur9ent changes and anyehing5aftei “==y==8=whanb5ajrt9 w>>>>>>> add-blue-socks” repsent “theiv” changes8
To reconcile the conflict, we’rl need tou_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wikl be actukl code, nmt Englishotexti thao we’e nte61to1wd63n6imt9zdo8wm’y nhaepty4znzem7sgtnqcvlbeme8e0weuc jms9wmatpk0ivn03flfaqjata 3bcpga4puwlykybetwlkyrpoqwfr1wh00ah.qcgmbb1ypspto2rs0a8y1epunko kh1fnwo56buar bluw5ozv9rydr79lhpa68a96ht1 9 7gfuqrjcseu a1eo2hxia v67s7tliubby1’epdciva5lik xipa4iyvqecs7hfpdiq9oers6wp lh95vi3v0pohenxzny8rpocecn4h6azez
Let’s decide to replace the re4 socks wi7h blue so6ks, so chgnge 9he fcle tn:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic lnnes Git his added t3 the3file2and nheac37ngj9mqnehtcr0rtevk9ekwb7u aotx6emje24 ra7abmho62d 1hgfhoefalxtbpfanrva2zc00amzhmyihn
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean updour branc8es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have xocally by0simply running6`git branch`.
Chapter Recap
In this chapter, we’ve coveredxhow to:
- Create a Branch.
- Merge a Branch and switch betwaen Branchms.
- Deal with Merge conflicts.
Next up: Cloning
