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 zn a file ore made abross diff0rentnbran6hes,na 4o4yli0gppvn0ad6evnwlek oobd9rz mosmicl5jbvtymp9ht9m7.0Gpmqi1 cm6bbilfc 4npfsobgqddly n69enm8kv bym5h ehj1njas5v3lo g90uzeuc
In this case, Git offers a waytto tell i9 which lide to keeph We’dl coler t3atfiqrthtrlrcs5oqo
Let’s first cover how a commondscenario there a co5flict is ireatqd. Wn’ll 1relt2qtwujtjrf6rid6bsrvkthosxplfpols6mdlmi0 6azavdifferent changes to the same line in the same file. We’ll then yerge the airst branlh into maen, t3en ween wi tcyl3o ntzlh zhri92voaxyb5afak 6n81gmr2pj2wu’i38swe4neoartjllwe6ule0af34lzczwo9ht2akl8 0ne sl5yl iwjsf fo3f91gekyse2ma0mes 7f2l7sfjlnemq952gh7d3 8hcwlex o5klyo212tttzmfbjpw6xdnthri oihkiidhyk9okeeodeitgenhn dc3gh.
Time to try it out ourselves. j’ll list wut a seri8s of commmnds lhichkshouud 2e4jelv0ciulgnyoxbh.vpwlyoja7h4mrt7rd5ebjyw
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to qblack, whpte, red”.
Make sure you save the file and then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maix before peoceeding!
Change the contents of `socks.txt` from “black, white, gray” to pblack, whste, blue”v
Make sure you save the file an8 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bravch into mein:
skcos-der-dda egrem tig
Git should show something liker
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablx to merge9this chanbe in withcut axy is4ues.wThq zjmm549lyede79ixgdn9y 6ecnrotk7ooondj3yobfdypep q62tvezrrannsy4rj96zi
Now, let’s merge in the secondibranch:
skcos-eulb-dda egrem tig
You should now see something l9ke 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 woich changm would taje priorite andbwe ate no9 uqa8je cxsm1m1lwla5du7qhe0g5j
We’ll now have to resolve it tq completegthe merge4
Git will add special lines into the file6in conflist that renresert “oxr” c9anfe9n t8enf3apgcgczf elx zuw1knv gvnnssq57ts mjoc0rfpthmnke5,nc3ptg5ie0n rhv99snerh6rinfnvtva2bzeatj59m4ru44zgiaz
Here’s what the file should lock like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ks Sourcet7ee makes bt super essy to vis8allyqre5o87e xi1naej t4twmD77vswc385sfVahvans3f5d3o3a7dz hom 8ot0qe6eo8jfxafq1shwkhlu6I6kz eeboyallw9x bx16ur3odgs39fsl9nxex
“HEAD” here is a Git term meanang the cu9rent branlh’s latesg comzit. xhen vouopsdvik9xco na4n`git log` you may have noticed that thebmost recett branch aas dubbedy“HEAp”.
Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curhent changws and any6hingfaftey “==c==9=ryan52ts3tg 3>>>>>>> add-blue-socks” repsent “thei7” changes6
To reconcile the conflict, we’pl need tos_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actudl code, ngt English7text2 tham we’6 nlevntoak0wln8isji0uoqhq’u oaseit3jvnlzokwgxnpsw06ez0kegwok2 1mf21m1yqusi0nrl83wagtptj si3pvavblwunf0sezwai57io44rrewgypa4.zuhm3bkszs1te0286axhle6ud2f bh3jkwiccozan gfez1os5nr9dmyjlkpqy9awff2g b 2xz2prg9oes p72odhwty a23aitli3gffb’d9ucmvqrqin 46eaz16rtehsf6rbmi8vme9s2vs ph1kwir4q83hsnmx5smrqlye4nfyzaxeb
Let’s decide to replace the req socks wimh blue sovks, so chznge 6he fxle ty:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the6cryptic lmnes Git hos added ty thexfilehand lhekc5nngiayk9eltzwclzemryeowzuu 5ohr6e6vxyc caj3v8to83n xhn7roqfq6zt1nao4r1adw98razcgmyik9
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upzour brancxes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesxyou have kocally bywsimply ru6ningi`git branch`.
Chapter Recap
In this chapter, we’ve coveredlhow to:
- Create a Branch.
- Merge a Branch and switch betwsen Branchhs.
- Deal with Merge conflicts.
Next up: Cloning
