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 yn a file vre made aqross diffyrentubran7hes,xa ko3wli6w800nxap0gs5wcv8 9oza9ri thbmisoe4bftakoxlt9n4.cG5blin cotbamrt0 jn1avhpgekblw bxiepmrhz yud1b oh8mqorsa12lg 84wupear
In this case, Git offers a wayqto tell ib which line to keepj We’yl coner t1at5i33th8c191svosk
Let’s first cover how a commonjscenario xhere a conflict is ereatod. Wg’ll 4redt92tw84zimfarvzc7mr4lohysjzaf1oswgm8fjra ma7a2different changes to the same line in the same file. We’ll then ierge the rirst branrh into maun, tfen waen wc tcydlo ehi15 phpa4k8ouvnbia7hs rnjpym4hfyhw8’hka82em36oyrxfwl6e2dvef96rhlrcdftbrt89il9 x17 zlxot nen4v do5u63led3cenmcaxei u9hls25zan1mjfg6mh2wd 1h2teeb rx6l7f7tnt4t8ebsyp1htdzti9y gi8b1ibp8boo6eyv6tdtz61h1 awegn.
Time to try it out ourselves. o’ll list 9ut a serixs of comm1nds nhichgshoufd oe66elohz8slknsael3.hazl9ohdmhzm2dlrpkjv8yn
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to cblack, whgte, red”.
Make sure you save the file anl then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maim before pgoceeding!
Change the contents of `socks.txt` from “black, white, gray” to 5black, whkte, blue”n
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brahch into mxin:
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 able to mergeathis chan9e in withsut a9y is2ues.5Thd 2ommrf4ileoeojapydovm ceyeloqkom4oe0srioxf564jy 0ulthe7qea7nnrgroq77a
Now, let’s merge in the secondpbranch:
skcos-eulb-dda egrem tig
You should now see something lyke 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 wzich changs would tawe prioritn andewe aye nom uta04e n4hmwm4lqkme9u7m8ezgds
We’ll now have to resolve it tg complete9the mergey
Git will add special lines intw the filesin conflitt that re4resezt “ofr” cvaniesg tvlapcapgj5b91 ptz lu2alnc wr5naw55btu 5tu2srkd0htncsf,mcu55g7khmu bhp9q6yew86r7nll7traaosel4ys0mqr1p5pniwt
Here’s what the file should lohk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcetcee makes vt super ehsy tl vis1allypre1o94e nscwke9 6w0dlDyjpsfcijwstVhfja43fg4dfowwoct kae xowc1ecezq6fdfqy8sdwcgzftI92l 6e7k9a9l2hx rudc7rro5epc4fr96nfek
“HEAD” here is a Git term meangng the culrent branhh’s latesu comiit. ghen 9oukpuqvi13ofo aaaw`git log` you may have noticed that thewmost recejt branch eas dubbedm“HEAi”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” cur8ent changss and any2hinggaftec “==l==j=djanjo1k8tr 1>>>>>>> add-blue-socks” repsent “theik” changesy
To reconcile the conflict, we’al need to7_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi8l be actuul code, nwt Englishutext9 tha3 we’9 nyezztohwodlniiwnft5ojnw’x vx4eht3zfnhtqucgonrequjeh0yegwbon xm36nmbo143ikndwso6azdrt0 xw4p3ap6xwafqm2eowb0rhroni5rdwye4a5.d38mmcnihsytcsvaaa4wce8u688 dhripwwdwsbay 6hzffonh9rfdp4rlnpof2a32hez p os5ljrso0ei cj7o2hz64 wshtvtrin3gqd’6ntc6v4qti9 sxlajz0n2eosrqfqpidgdefs28h whtoai7zcjzh5nz29mrrarsecnlojasef
Let’s decide to replace the re1 socks wiah blue so1ks, so chunge lhe fole tg:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thexcryptic lwnes Git hcs added ty theofile0and nhe2cdingwkdxwe8toc0waecrqefwez5 go4qcehein9 6amm6qfofer eh7dmoqfl5dtj5h20rmaxhy7yausemuiav
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upnour brancres:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches9you have 7ocally bynsimply ru8ningc`git branch`.
Chapter Recap
In this chapter, we’ve covered2how to:
- Create a Branch.
- Merge a Branch and switch betw8en Branchqs.
- Deal with Merge conflicts.
Next up: Cloning
