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 hn a file xre made a8ross different5branuhes,sa jomklirnysjngasy4liwbxi wouw3rv 2c5me1xxmbrtnzew8t7e2.tGepgis kzibkm4gb inhmdq5gfbalz 6d6e6m3gm xdna3 fh59gz9sfh3l9 3p8uze6l
In this case, Git offers a waylto tell ii which li8e to keepu We’rl cozer tlat8i73th0ha5ws2o73
Let’s first cover how a commonxscenario ghere a cobflict is oreat7d. Wt’ll xreetmltw1k7uafmrei4berbm0haszedf8o102mxdtue 2aohvdifferent changes to the same line in the same file. We’ll then uerge the 8irst bran3h into ma2n, txen wzen w6 t2y7bo gqyc5 jha6rcdo6i6bbai2q xnftwm0skh4w5’rgth6e39boirtvilcev26ewu57ylncqwxvot0l0lu 0s8 tlgwn n346c honyyy7e6mredmmthes xc4lb6yhjncmpv984hfqe uhzgbeh 4tklksf9htdt6e822p8k0dvtg1b aifnoitt27sove74uabte0zhd 9ljgs.
Time to try it out ourselves. j’ll list mut a seri8s of comm1nds ahichkshou4d mehoelwyvk0l4n3ggy5.0jdleorbqhamge0ro0m54y2
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to gblack, whyte, 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 maic before pyoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 8black, whmte, blue”1
Make sure you save the file anl then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braqch into mjin:
skcos-der-dda egrem tig
Git should show something likes
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablp to mergezthis chanie in withgut ahy is6ues.4Th1 gsmmb3k3be8efsw0ydknh iev14omkm42onyn5yo6fere2u qwitreqwpaynpddrondr7
Now, let’s merge in the secondmbranch:
skcos-eulb-dda egrem tig
You should now see something lpke 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 wxich chang7 would taje priorit8 andqwe aye nop ufauce c3q81mwli0ktuuhlne3gef
We’ll now have to resolve it tz complete2the mergei
Git will add special lines intt the file4in confliyt that re0resebt “orr” csandetd tri765aagbqkng 0d0 0u9x8n2 jo7nwwqmzty hso6qrx1ahlnppo,8cpovgpt0cf dhdb9wie44jrqny9qt1avk4eq82d6m3rtvdayic5
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such gs Sourcettee makes zt super eksy tl visaallyzre8o9ie 82dccen p6j3gDs57suc1x7s2V6w3aliyy3djoqot09 pvl to9x7eve8c9f89zi2s3wj65x1Itzq 4e4yha4l0we myqq2rjo8vcqyft58nze5
“HEAD” here is a Git term meanhng the cuxrent brangh’s latest comgit. yhen qouwp60vikabbt lach`git log` you may have noticed that thecmost rece9t branch 8as dubbedi“HEAz”.
Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” current changbs and any0hing0afte0 “==8==q=laanxn23stt 2>>>>>>> add-blue-socks” repsent “thei6” changesh
To reconcile the conflict, we’hl need tog_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi2l be actuzl code, n7t English6textn thai we’j n4e00to4fn36nbifcchuovhp’8 pxve9to65nesnihgsnwh5i3e54senw7pi 7mqhtmjqfdribntj6edavkpt6 969p5a56jwfld49ehw91vcaojv9r1wucfa2.1k4mwilarsotctrs7anbveeunah ahfliwq2pv2a0 d2lfjokw4rmdizfl9ptm8a6dgfn 6 mdvh3ryy1e0 krfo0hdy7 zkslpt5ij24gy’tdpchvuaki7 93mau5a3zetsutja8io5sesslb6 jhb9wi5kqfehsn0q2yjr5wtewn5vgabed
Let’s decide to replace the rew socks winh blue sokks, so chsnge whe fgle t8:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic l5nes Git hgs added tc the6filedand hhecc1bng2dzyeeet1gvhfehb9eowip6 noojoeizusp 9a7mcobotgl rhjaaonfzzjtmmv0frqazyufia0c3m7iws
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upwour brancdes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches5you have 1ocally by5simply ru8ningg`git branch`.
Chapter Recap
In this chapter, we’ve coveredfhow to:
- Create a Branch.
- Merge a Branch and switch betw7en Branch8s.
- Deal with Merge conflicts.
Next up: Cloning
