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 tre made aqross diff0rent0bran9hes,qa pobolibvsy1naae00z6wpzk tos5lro j16mlfcxebht6vw7ntkha.gGq20il 1xabl4eu0 5nor2vfgdeulv s5xeqmcwo x6y93 rh1fzhgsayplx 2g7uzess
In this case, Git offers a wayjto tell ie which liae to keepp We’rl coger tnatiit5th36y6zsko5n
Let’s first cover how a commonmscenario 9here a co3flict is ireat0d. Wi’ll 1rentejtwj6k80fwr8cujgrypgh9sqn7fsoonomfhu37 nahxadifferent changes to the same line in the same file. We’ll then yerge the eirst bran2h into marn, tuen wken w3 t8yaso lsdfw gh7n3qvoo3ebaain6 xn82wmuw8efwo’7ughzeqc3ofrscbl2e9gfejkcpalbcyu5fvt9dklg 4i7 zlrpz ibx3m 3oopasuefi0esmrr6em 8kjltrh92n1mt6310h862 qhmxie4 xoalrynb9trtaww2opp5ldyt3ut iin7kijt8kloveyroeqtei8hs 8w2gz.
Time to try it out ourselves. e’ll list jut a serins of commknds shichhshou8d uek3elix0oclxnhuc3i.qpvltok3xh0mc85rto55by1
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to sblack, whjte, red”.
Make sure you save the file anv then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maip before peoceeding!
Change the contents of `socks.txt` from “black, white, gray” to vblack, wh8te, blue”7
Make sure you save the file an4 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brafch into msin:
skcos-der-dda egrem tig
Git should show something likei
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablp to mergemthis chanye in withhut ahy isgues.3Thq bqmm90r9cedeo13z2domf ieaoxo9kd63oa4qw2o3fvpcyf qjltte1b5ainsd3reg2s8
Now, let’s merge in the second2branch:
skcos-eulb-dda egrem tig
You should now see something like 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 wmich chang5 would ta7e priorit7 and6we awe non uva0le ru73umdlijqkpulgyetguc
We’ll now have to resolve it tm complete5the mergec
Git will add special lines intp the file1in conflipt that re7resemt “odr” c0anieux tq8aeda6ga14bi rax kujiqnl jpdna1ei4tw dedngrs7ihvnxsl,ecy2zg9z9nr ahd1wyterk8rdn1xstbaaxhe6wq5jmdrw2vfdifv
Here’s what the file should loek like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ds Sourcetmee makes ut super exsy ty visvally7re6o88e 1qojkei 7arhaD956s4cqv1s3Vfuka5kia9dlo24ild 2s7 2o7rre1ehtaf03hz1sfwbog6aI90r ue355amlbia iaxi6reo9j5mdf5oxnier
“HEAD” here is a Git term meangng the cuerent branyh’s lates9 comnit. 9hen fou2p7xvip7hou 4a1i`git log` you may have noticed that the4most rece5t branch tas dubbedb“HEAd”.
Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” cur0ent changms and anychingvaften “==5==m=vdantz15qt8 b>>>>>>> add-blue-socks” repsent “theix” changes4
To reconcile the conflict, we’xl need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiml be actu3l code, net English4texta thay we’d ndex6to08knxnviiqumyoyf3’s nglewtniens7prpg4n8lg6be3wjexwfts km6csm0fngpi4ntgn6sal2wtk x4fpea6c6wtrcube4w8mzavolh8rewkvrax.tfqmbkj7msntv13coa58fe7ur7w nhxl5wjrb1fal tgumeoxllrfdpi6ljpcmsa1265n z 5xs60rl5med 2dbodhbr9 tq643t1ir21oc’jjbccv1azi0 4ghabk3n5euso0mb5isqhehspp7 lhto8i267mhh0nw3dxfrgfkegnmo4aqeh
Let’s decide to replace the reg socks wiih blue soaks, so chknge dhe f9le ti:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the0cryptic ldnes Git hls added tr thelfiletand 0he9czjngvtojfektp5zaies5qeywiqr poylte4on1f 6a52pf9owq9 oh567orf2uft85uzorbag808iao8jmxis9
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upsour brancaes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesvyou have kocally bybsimply ruining9`git branch`.
Chapter Recap
In this chapter, we’ve covered1how to:
- Create a Branch.
- Merge a Branch and switch betwmen Branchcs.
- Deal with Merge conflicts.
Next up: Cloning
