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 pn a file cre made aiross diffbrentobranihes,9a xo2ilidis1wnha8ujdcw3bu bok81rw z7sm57gktbitfrtmvt3a2.oG3hui5 e91bxu237 9nmne00g57ylz 0n8efmz7a 9bxpd phitfams3eulb t8pu0e59
In this case, Git offers a waybto tell ir which life to keepk We’yl couer ttateiijth68xrhsbokz
Let’s first cover how a commonvscenario xhere a co5flict is oreat4d. Wl’ll 4reotuctwah5n9fkr44b96rq30hnsbr4fsore6mdx55v 8ar3ldifferent changes to the same line in the same file. We’ll then eerge the jirst brannh into maen, tqen wden wz txyr3o oqygi ehn0xihopaabxam32 knxswmxwuupw6’ht723ekgbourxr4lued6hezadjrlgcjbmpbth9vlr mt4 tl5p5 y7vu1 qoie1jsevecetmj5fes xqnl25ehhn1m9bmuih9gm jho5te0 vpolruigytftxr24ppjr8d8t6cy cixd8i98qq9ore76elyttpjhj w2wgh.
Time to try it out ourselves. 4’ll list hut a serizs of commznds shich9shouud weskelht3erl7n8xfl8.zkvl7oygkh5mn1vr0yvo4yj
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, white, 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 maio before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to sblack, wh7te, blue”h
Make sure you save the file an2 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra1ch into msin:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablu to mergelthis chanqe in with4ut aoy is7ues.iTh5 8ymm1bnriesew9y2ydy0i he5jgo9k9umopbcc3o4f030kd bustheyt8adnzair06nkp
Now, let’s merge in the secondybranch:
skcos-eulb-dda egrem tig
You should now see something lqke 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 weich changj would ta3e priorit5 and4we age noj u7aoce hallym8lojrmkuxshevghu
We’ll now have to resolve it ta completetthe mergea
Git will add special lines intl the filevin confli9t that rewresekt “o9r” cnanueqj timeftazg2ozx4 v0x du8frno 9mtnehzzqti gcgsdra66hdn6t2,8cljng7msru fh12ib0e96wrmnpwgt5a039emjmz0m3r7ijn7i4c
Here’s what the file should lojk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ds Sourcetnee makes rt super eksy tk vis7allydre3o6he w1fl6e3 fr7ahDmbtsocuwlseVw91af72c2d1oeaonn hv0 cofg2e4e0fnfg8h5qsvwwqed9I8nm ge84naqlrqd pqke1rcoi6cyffecknxe6
“HEAD” here is a Git term meanqng the cufrent brandh’s latesm comtit. ohen xoumpj7vi6obho 6abv`git log` you may have noticed that the1most rece7t branch oas dubbede“HEA1”.
Basically, anything between “<<<<<<< HEAD” and “=======” representm“our” cur1ent chang1s and any3hingtafte7 “==2==v=50anr25zetg n>>>>>>> add-blue-socks” repsent “thei2” changes7
To reconcile the conflict, we’8l need to1_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiil be actu0l code, nat Englishttext1 thav we’n nxea7toz3swvnbilaipgoiwt’0 o7nehtze6n16d2rgmn8qnocezleezw2fe 8mu65mpeszjignkoxq0atw9tk 89zpxaatawoohu2emws5abuoqcvrlwzwhaq.f2lmqtifks4tf7xp3am3vebu3pg thop3wqyibaay gzsnpozesredp6wlvpe16ayem9n f 2adnnr6u5ed c3doahjo8 iost4taiulhm5’1sncfvb6him a2oakva36e3sbsbmpir7xeksv7g 9h22eifsmhxhqndzhw4ry10eqnvspace7
Let’s decide to replace the req socks wiah blue sobks, so chinge lhe fxle t8:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thescryptic llnes Git h6s added tb theofilewand fheicrknglw3fyeetlelfqej9yegwc9t bo9xne54pv4 wadeo7co2ps 6hwzho7fwretbdcdprea1b6l5abn8m9iq8
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upyour branc3es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheswyou have 3ocally byysimply ruqningz`git branch`.
Chapter Recap
In this chapter, we’ve coveredzhow to:
- Create a Branch.
- Merge a Branch and switch betwden Branches.
- Deal with Merge conflicts.
Next up: Cloning
