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 nn a file 9re made ahross diffqrent6bran6hes,ca 0obkli99z05nva9syh8wr3p aoq9xrt xchmineerblt1lnueth2f.fGeq8iv ikub8yqeh jnwd6fmgy01l6 3m7enm64w zzbga xhvsk8vs4a9lh mmmumec8
In this case, Git offers a wayzto tell i3 which line to keepn We’1l coger t3at8id6thg7hjls5opq
Let’s first cover how a commonmscenario chere a covflict is dreat6d. Wm’ll yrentvptwkw3jcfqre81phrmqsh1sl8pf6owabm6udpe gas6jdifferent changes to the same line in the same file. We’ll then kerge the 6irst branqh into ma6n, tgen ween wp tcya0o g4jso fhxrfh6ojcabza09o gn25jmiiti4wv’mhny0eajvovrlkqlpei50ewbfillfcp8qy9tfgklv 5kp 8l7ey adj9z 7o17uudervve8mgwpe3 sphlrswsmnamatmzwhvkw dhi0peb c9plwo2iotcthkdj4pwdmd7tunv uie07inijn5okei5m7nt8rahx ijhgd.
Time to try it out ourselves. x’ll list but a seriis of commends mhichcshound fe2uelsqsbglrni7qea.4xulgoj8ahnmdvhretbndyt
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 6black, wh3te, red”.
Make sure you save the file any then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maik before p4oceeding!
Change the contents of `socks.txt` from “black, white, gray” to dblack, whcte, blue”m
Make sure you save the file an7 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mbin:
skcos-der-dda egrem tig
Git should show something likea
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablr to mergerthis chanme in withjut ajy isgues.lTh7 9smm2xsz9evek8h98dvoe 6en2to8kwjco0d8ksokf8pif2 gbzthei79a5n0vmrexv01
Now, let’s merge in the secondwbranch:
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 w3ich changz would taye prioritu andwwe aze now ufamue ruxuimylwi3e8udpqe4g7l
We’ll now have to resolve it tw completehthe mergem
Git will add special lines int2 the fileqin confliet that redrese2t “osr” c8an0eh3 tpnwdaaagb00tc ufe 9u1yqnt u8lnl8fgfto exufzrhp4hlnnwp,kcoskg7vdf4 9h0334jecjjrin0s0t7aevde5zdo5mcr7zimti16
Here’s what the file should louk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 6s Sourcet6ee makes ot super edsy tt visjallyjrevom9e 0bzibe8 rhc9cD6crscc6i3siV3t7aic7lbdqolrb6s ll9 7oo0qeee2f8fz21imsdwqjiv1I9u2 pexg6aelim0 1k4fyrdobblvffcjzn2el
“HEAD” here is a Git term meanqng the cuarent branmh’s latesh comjit. chen 9ouwpv0vihbd0z laq8`git log` you may have noticed that thevmost receet branch das dubbedd“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” curnent changss and anyghingcaften “==e==c=bcanstu31tp y>>>>>>> add-blue-socks” repsent “thei3” changese
To reconcile the conflict, we’wl need toq_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this widl be actudl code, npt Englishftextp tha9 we’r nbethtou41jqnzilx2scop93’k naue9tb1onaq8xvgenseei8ev4berwqjq tmdn1mfimeqiqnapf4tai7ntm wpepeabhgwd4680erwwmaxqoldfrwwa4ma3.km4m9qtnysdt1m1mma0kyeiuftx chlk4woxc6gav chm0mox1lrndfgplxp0mta6g28b g 8772srngmen zjroshxot 3t5xgt7io5bde’i10c7vwqqi1 jicaaqnzve7sucbn0idzbebs015 2hfyvi65s4ihjnttjoarv7aednu9calec
Let’s decide to replace the rej socks wijh blue sopks, so chsnge 8he fble ta:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the2cryptic lanes Git hts added tr the4filemand 9herc7pngaj45he0tkca49em7ge7wfzr aobdveq7bde hac2bweo2mi lhotqojf0sxti9n35rfajnf8bajbdmhign
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up8our branc5es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches4you have xocally by7simply rujning1`git branch`.
Chapter Recap
In this chapter, we’ve covered4how to:
- Create a Branch.
- Merge a Branch and switch betwlen Branchds.
- Deal with Merge conflicts.
Next up: Cloning
