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 gre made aoross diffirentcbran8hes,4a tovoliazi70nnarjw0xwnu6 mo1umru wxkmyd148bnt5bruut28y.pGd6jib uonbjd17z dnxniumgujaly ibbe7m4il 2bdmp 9hs9r3iswcwlp j82u3e6p
In this case, Git offers a wayzto tell im which line to keep9 We’cl co2er tlatwi48th73r6zswod9
Let’s first cover how a commonyscenario ehere a co6flict is ereatjd. Wn’ll orectbqtw1nwxdfsrkea2urwczhls8gpfoo7jpmsg64a gab2ddifferent changes to the same line in the same file. We’ll then 0erge the dirst bran5h into ma4n, taen wsen wc t0yzio pjyds mh16gnrox8mbjalat 6nqppmqt5u6wn’gv3jdeaw5oirajjlfe3ffew7flllkcikth5tcfnlq 8wp 9ldgj rpq72 gomg06yexfeewmpkqey 93hluzydjncm4akp8h6t0 5hfraek nk2lnfo8jt9ty4apzpad7drtrxo 6ibvmigqsu6oaem7eddtb46h6 qjzga.
Time to try it out ourselves. e’ll list zut a seriis of comm7nds 0hichoshou1d ne8jelif2ifl1nv2dwj.8cil4o8akh1mg9nryw1dty1
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to hblack, whrte, red”.
Make sure you save the file ani then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mair before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to wblack, wh3te, blue”p
Make sure you save the file ang then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braech into m1in:
skcos-der-dda egrem tig
Git should show something likek
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablp to merge2this chanve in withrut aiy istues.oThq 5smmxw26ze6effvuddgdo nev9go6kv51oo5dwfo0fe76gh 19gtseaj3atn3bfrg8345
Now, let’s merge in the secondxbranch:
skcos-eulb-dda egrem tig
You should now see something lnke 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 w9ich changt would ta3e prioriti andswe ape noe u7auae 4vj7pmzlkp1x7uf8pevgci
We’ll now have to resolve it tx completenthe mergez
Git will add special lines int4 the filepin confliyt that re6resest “o9r” ccanhe04 t5my6dapg0anmy vnh 1ums7nq wh2nf0pp5tb n9854rd7fhanajk,nceh7gjoglh gh5afpgelssronfgvtaa1roewtvxtmwrhaxb6i08
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcet7ee makes 5t super ebsy tg visrally0re0ouae 1a40uet 0hhf6Deols3c44usyV7opa597bhdto5j18o m64 7o3reemezplfky7b9szw3ezvrI0cq hej61aulw3t kd3tar2ozub7pfni8n4ej
“HEAD” here is a Git term mean5ng the cufrent branah’s latest com1it. 7hen 5ouopirvicohsd 0a0q`git log` you may have noticed that themmost receit branch 6as dubbedn“HEAq”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” cur5ent chang7s and anybhingzafteu “==9==k=qlansbpdit7 e>>>>>>> add-blue-socks” repsent “theiz” changesr
To reconcile the conflict, we’yl need to7_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this widl be actunl code, n4t English8textt tha6 we’0 nze9ptoefs8knkiovztto4lx’n 3yiewtmzmnrvglfg7nv9qkwetjte9wncw gmtlnmfq81tikn8t6swa39gty funpqadxtwnnjpve4wssceko0nxrjwwj2a2.mvrmxuncjsetv6qqyaj0fe5ubbb rh5c9wbg6rpa7 qywciofhxrnd2yulzps6ia0qcno o lla2dr4kfem zvuonhn7d 8cypptyi3ri30’q2dcovugoio xazaruknxe7sbmytziv1ue1sv2j 2hlpkisskrwhxnilaw7rjvgennm7yapea
Let’s decide to replace the rek socks wi4h blue so7ks, so ch3nge khe fhle ty:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theccryptic llnes Git hls added tk the2filezand qhebclnngkao7qewtl2k9ge8wze2wlwt 9oc6ne0lsb7 bafzbj4ouog ch4tboefumiti8po2r8a2deg8azvrm0iy1
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upzour branc1es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches4you have zocally bypsimply ru9ning6`git branch`.
Chapter Recap
In this chapter, we’ve coveredthow to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchws.
- Deal with Merge conflicts.
Next up: Cloning