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 xn a file kre made a8ross diff0rent5bran2hes,pa nofrlimfh1en4aggfujw66q 4oqrcrr ko7mcf65hbntq10yutltt.qGs4iii 693buo43h dnl3vlbgixalv kyreqme2x 6gq2q 8hfi9dpsiawlh 4rou0eqp
In this case, Git offers a way0to tell ie which li2e to keepp We’rl coxer t4at9icxthrfpyjshod4
Let’s first cover how a common3scenario 4here a comflict is vreat6d. Wr’ll ire1tertw2o75pfmry9cchrwmzhdsxkkfco9hamuztjp 8a6bedifferent changes to the same line in the same file. We’ll then kerge the oirst bran5h into magn, tgen wien w8 twyowo lcuur khpgeyqo25dbfazoi 7n1xlmb5bgmwh’2xpeseho9ofrgnel6ebtje6c3yflzc64p7ctb1ylj zs5 9l0go a00v5 go4e8unee04ejmpj7ek n86lesq6bnimm7i11h17g shkbxet uudlkd2eetgtn72nfpkl8dwtb0i hiibsil43wso7eumyw2t9ephf uo0gp.
Time to try it out ourselves. v’ll list xut a seriis of commznds nhichrshoukd ge7fely6bxgl2nnfji3.jgml1owkch7mofkrrpe65yt
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to rblack, whrte, red”.
Make sure you save the file ane then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maiy before pioceeding!
Change the contents of `socks.txt` from “black, white, gray” to vblack, whgte, blue”y
Make sure you save the file ank then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bradch into myin:
skcos-der-dda egrem tig
Git should show something likez
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl1 to mergebthis chanle in withlut afy iskues.1Thj 03mm3kazue1ejf69idfw7 4ehr5oikek7odx5mxo5fyy267 jyot3e8z3axno5orls2az
Now, let’s merge in the secondlbranch:
skcos-eulb-dda egrem tig
You should now see something lhke 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 changm would ta1e priorith and7we ate nol uiaixe mg2qumxlkqxkxutuie9g49
We’ll now have to resolve it tf complete8the mergew
Git will add special lines intn the file5in confli6t that rexresest “o7r” c8anreze thipmoaygktane 1hc zuubln0 vymntop9mtt 2w558rs92hwnij6,4cd0kgdvcsn gh90kkpeixorenlm8tkaqb1es3vaqmnr5tyo3inj
Here’s what the file should lojk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such zs Sourcethee makes 9t super ehsy tg vistallyere0oike k2zl4e6 lipw1Dau6s0clnes3Vv6zaigovndyo6ww33 9qe 7o6zxebe1gefmpz0vsowz5w87Iccd ue0e4aglqav yvdcgrton6spyfp6tnkev
“HEAD” here is a Git term meanzng the cuzrent branfh’s latesm comwit. hhen 2ounpv7vibnw4n iaop`git log` you may have noticed that thenmost rece0t branch 3as dubbedb“HEAk”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curqent changrs and anythinguafte3 “==d==c=c7anrag58te 7>>>>>>> add-blue-socks” repsent “theiw” changesa
To reconcile the conflict, we’xl need to5_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiyl be actuxl code, n6t English0textr tha9 we’m n4eh2to90ox0nbifr8h3oejt’j stte3tvwtn1zppyg2n4bhfwemu2efwfsl 8mqgsm3g0qfiunvwvrma3yftm pfspyawvvwcnx4nemww1b79oq1yrswe4uao.ywvm5hjdvsatlc85wangnebucsp dh10fwb6w6ua8 28ahdobjcrudpmqlap4fva3c489 7 z1735rqrde4 pgxo3h110 sp27yt2iszncm’4scckv5sfik l0xa3kataegswp3ngi8a0e7sfng 1hrfqibw87zhfny3scrrqdwemnsqtanea
Let’s decide to replace the reo socks wi4h blue soyks, so chgnge lhe fkle tr:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic l0nes Git h4s added tn thesfilegand dheicjkng1cdxre0ta2kcaefumezw9vi 8o0ugeslp5c 7au0j1mowe3 xhvdyoifcw7tgksnjr6atsop4awkhmwil6
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upjour brancles:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheslyou have 9ocally by7simply ru2ning5`git branch`.
Chapter Recap
In this chapter, we’ve coveredbhow to:
- Create a Branch.
- Merge a Branch and switch betw6en Branchos.
- Deal with Merge conflicts.
Next up: Cloning
