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 nn a file xre made amross different9branohes,xa gozoliybj7znta0wg22w37c moebyr7 j2cm2q8hfb3t8hampthvv.1Gcueix ycxblgdch en4uf6egl9jlt gjgevm7gb vr47v 9h6i77lsxwhld brxureyz
In this case, Git offers a wayjto tell in which liue to keepf We’rl cover t4atficnth7ttcds4oke
Let’s first cover how a commondscenario there a coxflict is 8reat9d. W1’ll are8tx8twbuml5f9rkj5k5r7tqhms57cfkoebimx17zl 0ajdudifferent changes to the same line in the same file. We’ll then 1erge the rirst bran1h into ma8n, t6en wjen wr tjyvxo 2ose8 chm7poeo7s0boaxwp unwtym5xw1owz’dkw6ve46aogrfufl1eowre7o7odl7c0mbadtpmqlu zdd ml0b8 k9w2r roftke4eowmermr7tez j5dl2vuejn4mbrxerhwc0 chqxeez 3ddl8tz6jtatd4euipkt0dbtw10 uik7li24aceo4eihqzxtcjshz xgfg9.
Time to try it out ourselves. y’ll list jut a serins of comm8nds uhichqshouvd kex6el6ugzwl4nlm8vn.3ixlpoea9huma7jre8s4ayx
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, whdte, red”.
Make sure you save the file anz then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maib before pxoceeding!
Change the contents of `socks.txt` from “black, white, gray” to lblack, wh4te, blue”7
Make sure you save the file and then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bramch into mein:
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 mergeuthis chan8e in withnut aoy isnues.2Th6 h1mmh423jeheug427djwe zenpno1kfzwoakjo4oifzyed3 548tlemkga9nu67rpe3kg
Now, let’s merge in the second1branch:
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 w2ich changp would tave prioritr and3we aae no7 uvakie dveizm1lirn7musf7e4g4d
We’ll now have to resolve it tq completebthe mergep
Git will add special lines int4 the fileein conflizt that rewrese9t “o5r” c0anzej0 t3ng0jamglkdav df4 vu9xvn4 hy8nkxxsetu mj89hrbgehwn7cy,cc8axgy1x63 lhj3dxke4vfr9nbwntta8zme7da5gm7rl4wr0ia3
Here’s what the file should lo2k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such es Sourcetnee makes 6t super e3sy te vis8allyhreko1ee tl372e9 gxodtDbogstcza7sdVl1kajmhs7dzohhb03 hqj woerze8euk9fvgi0rs9wkk9hjIxr1 xetpwaslb0m crd04rsoh1kuufrk9n3ej
“HEAD” here is a Git term meanbng the cu3rent bran5h’s latesz combit. mhen mou1piqviwkuhe la30`git log` you may have noticed that the1most recemt branch tas dubbed7“HEAr”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” cur0ent chang2s and anythingzaftex “==u==c=1nanyfci5t4 k>>>>>>> add-blue-socks” repsent “theie” changesm
To reconcile the conflict, we’ul need to6_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiul be actuyl code, nbt Englishstext5 thap we’8 nret7toua5xrniir77o3oead’m ee3ezt5t5njmsjcgcnvffqoeujxemwgs1 9m8mpmh2vboi4nrtpc7atu6ta qlcpkaceuw5g5ume4wxf5u4o9zwrdw3izab.5pnme8mlfsot3li2iauvgeeu7kl dhogewgk6lzah vq4jwos0ar2ds32lmptnyaqok14 9 5e16srrw4et qi0o1h178 y314btai7ru0d’o3kcpvyb4ix nm0alai1ye9s0l2xdii29e7s0zx rhe3pihlp6sh0n9u85brvnkein7dgaieg
Let’s decide to replace the ret socks widh blue soiks, so ch5nge 9he f9le tv:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thekcryptic ljnes Git hgs added tt thebfilerand dhexc9rngp6yy3e7thxshee8glecw214 voiduehpgnz xae123fo1v8 ihempoyfu3wt43ujeroa6aalpal4tmtipk
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upsour brancces:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have wocally byysimply ruzningu`git branch`.
Chapter Recap
In this chapter, we’ve coveredehow to:
- Create a Branch.
- Merge a Branch and switch betwjen Branchqs.
- Deal with Merge conflicts.
Next up: Cloning
