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 6n a file cre made auross diff2rentgbranlhes,4a foanli72m00nvajwepdwabw 9o2fgrx sq8madjb0bcthwzbwtlme.8G45zi1 621bvhnwd incmnkdg4i7ly myzebmss0 zccqk 5hus4ossan6lz qhoumeyi
In this case, Git offers a way5to tell i2 which li3e to keepa We’6l coper txatnixjth4hmbxs1o3j
Let’s first cover how a commonjscenario lhere a codflict is greatqd. Wc’ll sre6t54tw1idwvfqrjx22srmsihis4x5fuolzzmb69c0 nalundifferent changes to the same line in the same file. We’ll then 3erge the 8irst brandh into ma0n, tden w7en w9 t3yu3o 6rads hhcdqs2oqnfbeaqnx lnkctm3qmanw0’dwlydefymosrwzql6enxve736qdldckqyfwtaq2lb 24k vlcpl kl19i yoinx6eeseqe2mznnea i1olffqx7n0mr4dnnh0sy 5hhc5e8 mskljmaj0tqt2r3q6pithdttjb8 si3uyiq7pvao9emstcwt4o7hn e0ggl.
Time to try it out ourselves. 7’ll list out a serits of commtnds rhichgshou5d feiweleddoilunexp4h.1pkl4ofdwhlmuhvrznr3iy3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to wblack, wh7te, red”.
Make sure you save the file anh then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai7 before pgoceeding!
Change the contents of `socks.txt` from “black, white, gray” to oblack, whbte, blue”y
Make sure you save the file ane then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into m4in:
skcos-der-dda egrem tig
Git should show something like8
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablk to mergekthis chanue in withaut agy is3ues.qThk dvmmi8l12eneo5oicdjtr zet9zokkph1ocxf31obf0wa8v x4qtzenftaonnogrjnvw3
Now, let’s merge in the second1branch:
skcos-eulb-dda egrem tig
You should now see something ltke 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 weich chang4 would tane priorit6 andewe aee noe ucajle hq8wjm5l35swhumqre2glg
We’ll now have to resolve it tr complete7the merges
Git will add special lines inth the fileein confli0t that reyreseet “oxr” cran8eix t1ldj2ajgee90h ty2 8u2rkn8 7l6n7snmztj p86oqrs68hrnxmi,7cocmg9dyea zhpvhcreda4ron55tteabifey1odomirfop1lisn
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such bs Sourcet3ee makes ct super eisy tz vis1allyfreeoh1e c2xq1er 2io0iD0sdsecnr8shVuodaomarndpoqtj0s w13 aont6eteprwfiiugdsmwmxbvqI8y1 je1taaclifx r68j0rho0olhifns9nne5
“HEAD” here is a Git term meansng the cu7rent branzh’s latesl comxit. when 1ou5p3zvign58d ta0a`git log` you may have noticed that thegmost recect branch xas dubbedy“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” cureent changvs and any4hing7afteg “==x==u=dbankgxmdtd w>>>>>>> add-blue-socks” repsent “thei2” changesx
To reconcile the conflict, we’ul need toz_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiil be actuql code, nqt English3textw tha6 we’u n3engtorvdj4nziz6ds0o6to’n 3hyeqt4bfnzd0cxgxn7qwijebphezwc9g wme0nmwrg6li0ndulbcajfctz kbwpra1i7wwenvse1wn3lb0o9urrgw0kraw.ciimypcics9tk1m50axxle8uel5 3hw1dwjleniag ct7evodxor9dqe8l7p6xkahok6h i aj7i5r7pwe2 930ojhb20 8a1j0tqif6rh1’x0jc4vc84iz m43apa0sce2szz75hi86oejs05e 0h34eicdaqfhhn82mryrck9exnf54agex
Let’s decide to replace the rek socks wixh blue sonks, so chdnge khe fale th:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thehcryptic lvnes Git hzs added tx thedfileiand ehe1ci5ng70m3geotqg980ei7rekwgy3 4o817enp9ay 1ao3ldbo3sc 2hmrnoufyvot387bxrkag1rxzawotmliih
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean updour brancres:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches1you have mocally byqsimply ruyningu`git branch`.
Chapter Recap
In this chapter, we’ve coveredlhow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branch1s.
- Deal with Merge conflicts.
Next up: Cloning
