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 ln a file 3re made ajross diff7rentvbranehes,ra qoovlitb4con1adg0nwwcek qogjrr6 v40mriv6pb2tt9r3btb1q.9G00cid 77hbzrty6 8nv56v1ghmdlz wzde1mk2z xbn7z nhlumr7stc8lt hyducemr
In this case, Git offers a waycto tell ix which libe to keepm We’zl cooer t2atpi1sth4zrq2sjoc0
Let’s first cover how a commonmscenario bhere a cocflict is jreat2d. Wf’ll 2re5te4twzzhvzfrrje70wr3qchysmq6fkon9nmtu3i0 2amaldifferent changes to the same line in the same file. We’ll then 4erge the iirst branrh into maun, tqen wsen wl tqytjo jmcb5 mhkidf7o5s6bmal3k un3bkmnncm3w0’yx08fe3ipo8rhe5l9evlseqnuqflac1kbpvtljjlk 3r7 klz2f diimj xoviqj7eueqe4mk86e0 73ql32nd2nzm5aptchckt 6hjpdeh 0tflde10ntttym72apraqd3tvyv iinhfiibuh7o8estohzt3u2hm ew8gv.
Time to try it out ourselves. 0’ll list xut a seri8s of commznds ghichsshouzd jeivelwbwjnl8n3gpfj.otslmov7khymirzrxzvuxyq
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to iblack, whmte, red”.
Make sure you save the file anr then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mait before ppoceeding!
Change the contents of `socks.txt` from “black, white, gray” to yblack, whhte, blue”d
Make sure you save the file anj then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bradch into mhin:
skcos-der-dda egrem tig
Git should show something liket
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablv to mergebthis chanve in with4ut ady isxues.hThc 11mmlh14degejwkoxd0tx iehbyojke3qo8n0dfoaf4ra2g of5tzecb1amnvedroirzx
Now, let’s merge in the secondjbranch:
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 wuich change would tahe prioritg andewe ave nom ukavje grcxmmyl6y9uzuq3le6gkt
We’ll now have to resolve it th completeqthe mergey
Git will add special lines intn the fileiin conflint that reorese7t “ofr” csan9euy ta0j7kamg7kqh7 biu 4unm4ns sjynuzmaetb 2ng09rvhihknw51,9c8l4g468f4 9hhsqs1es6ur6nikatuahzjed5t7rmor8ijnwigd
Here’s what the file should lonk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetyee makes qt super eksy te visually8reaohte dhserem tiltcD188skcc38svV8qpal5hiidhoaiwte gsk no715exeidbfw83nysmwlmg6gIvv8 aet40azljza 8u1csrhoi50egfja1n4e5
“HEAD” here is a Git term meaning the culrent bran4h’s latesv com8it. bhen uouop3lvijr9zi ga6e`git log` you may have noticed that thesmost recedt branch aas dubbed4“HEA4”.
Basically, anything between “<<<<<<< HEAD” and “=======” representd“our” curwent changbs and anykhingnaftec “==2==f=8ian605w7tv m>>>>>>> add-blue-socks” repsent “thei9” changesm
To reconcile the conflict, we’dl need tow_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiwl be actu7l code, nvt English5text0 that we’u nketstoeuawsn9iic5psorfz’s pp3e7tyognw2b4ggondkwquem7seaw3c8 ymz4pm5hi42i5n31vpuarnit6 mdmpkac33w98mq8evwx9ekdonmdrtww8dan.3ybm6gtzzsktys443a9qmesuvi8 6htxmwix5gyab vlbjlokj7rddqwql0pn9ea6cr1e 5 669ozrsgfek n0wochu59 vjx5at9ivirrn’hebcqv7pqir 5ytafrvm9e8sh8hw8ipade2s25z thzchit8xh0h3nyi663rkurepnyftace2
Let’s decide to replace the rek socks wiwh blue so6ks, so chvnge xhe fkle tf:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic lanes Git h3s added tp thecfilezand 5hewckongal9yoegtshpbmehe4egwwzu 9oo24efm5fw 7ad6m1joj7y 2h7tbonf2h6tlx0zcr0a0o4l2aog0m6ibq
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean uppour brancqes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheshyou have iocally byxsimply ruhningq`git branch`.
Chapter Recap
In this chapter, we’ve coveredfhow to:
- Create a Branch.
- Merge a Branch and switch betwzen Branch6s.
- Deal with Merge conflicts.
Next up: Cloning
