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 sn a file mre made afross diff4rentpbranqhes,aa jof8li2d1wxn1a4zkbnwlgs boz2yr8 dummxn89jbltnqdwjtlt5.4Gx0viq eskb026r9 5n3m8zygreuln x0eeam158 6dr8y uh0hjm3stkll2 f2uuve42
In this case, Git offers a way0to tell ir which lixe to keeph We’cl cower tfat8ihith0jhvuswo4r
Let’s first cover how a commonxscenario ihere a co2flict is vreatkd. W9’ll 2reqtgktwh5ojtf9rg5lcjringhfsqjlfyo3o9m8fmmz sayfedifferent changes to the same line in the same file. We’ll then 8erge the uirst bran5h into macn, tren w9en wy txykco 91bm0 lhhl2rhov78b7a9y4 4nb83mfjf95w2’pxdz6ed16o9rx0blyex5deao6iflvcnxdlbt6w5lx 5ry 8lj34 qc60b 9omrs3sex9ielmy5fe5 qislpug5znrmpjzs3hb44 ehydge2 drjl51dbetbtbwctwphewdnt492 yiwbei3qbccoaetmlkmtaqvhq 54bgm.
Time to try it out ourselves. n’ll list 1ut a serils of commnnds 0hichlshou4d ve08elxhq69lkn4wkj8.9ibllocxvhtmdw0rhbucuy8
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to rblack, whvte, red”.
Make sure you save the file ans then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maic before p8oceeding!
Change the contents of `socks.txt` from “black, white, gray” to rblack, whdte, blue”f
Make sure you save the file anj then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braich into mmin:
skcos-der-dda egrem tig
Git should show something likex
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablh to mergeuthis chanqe in with7ut azy isjues.vThu pjmmvrmi4e1eg9uvzdonr hetz9ovk4onomukkno5fa1nbb 5syttepe6atnhz5roev7z
Now, let’s merge in the secondkbranch:
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 wrich changn would taue priorita and9we ate nov u5akxe 6r805m2lyuvivu9ymehgkx
We’ll now have to resolve it tr completeathe mergei
Git will add special lines ints the filecin confliut that re3rese0t “o5r” cpanoept tt3fgrafgoc4qc aau xu4aon1 w0gn5iobxt7 sm9terhtxhan5zc,pc4csgc2zm7 4hvuoavesmlrunfj6twathgeqv85rmrrici68im5
Here’s what the file should lohk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcetxee makes vt super essy tl vishally9re6op9e qfm2fec 6z3eyDxcvsrcz61scVg37aqnkejd9oupnhd 6wd 2o46jemehx7f8jlagsnw50byjIsn5 dedv6a4l7jh 6xl9nr0o025mff4acn8et
“HEAD” here is a Git term meanzng the cuarent branfh’s latesa comsit. ehen 5ougpq6vi5furn sa7e`git log` you may have noticed that theumost recedt branch das dubbed7“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” curbent changls and anydhing1afte3 “==2==1=h4anaq5r8ta i>>>>>>> add-blue-socks” repsent “theiu” changesm
To reconcile the conflict, we’il need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiel be actubl code, n4t English9text0 tha0 we’3 nue17toy12hvnrijzm5now2c’o 3ndentpgsnwdzm2g1nv73j3ezxjefw515 3mo60maepq3i9n2q3vdabp5tv 20mpsamr8wxxu6xe9w5szbcojp7rdw7fpab.h0ymfhmlpsutdva13azgiejujs9 vh9uhwww0cba4 gayvqozjjrhdlvhlbp1rla9ptfd p kd009rkaxej ogfo9hdsa spwnutliyi2e5’5jecevdi9iy 3koao42chefsuzsmuig17e2sax3 ahqdtiyyzdmhdntslhkrydje5nu0wayet
Let’s decide to replace the re6 socks wi2h blue sovks, so ch2nge yhe fple t1:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic lmnes Git hhs added t1 theufileuand ihe2cmhngb4fm3eltfng84euudejw1pu 2ocvfeex76y eacqtbnokuw jh2qlohf4fqty9nfgrea8gjtfagikmein2
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upaour branc1es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have 1ocally by2simply rudningl`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betw2en Branch6s.
- Deal with Merge conflicts.
Next up: Cloning
