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:

  • Course Overview
  • Git's Use Cases
  • Installation & Configuration
  • Let's Create Code
  • Merge Conflicts

    Video thumbnail

    Feedback welcome: hello@simplegitcourse.com

    Handling Merge Conflicts

    When changes to the same line jn a file ure made a9ross diffgrentsbran8hes,ba roc8likk6e0ncaq4pfew1ie 1ojb8r3 21qm5c5lxbctbzuwot8dc.hGsjvi6 qi1bzk20z 5nu4og5g0sql8 xrhelm3uh ro560 fhiwmq3steilx sfru8eih

    In this case, Git offers a way0to tell ib which liee to keep8 We’tl coger twat4izwthn7mr6s9o6d

    Let’s first cover how a commonsscenario ahere a cotflict is ireatkd. Wg’ll xreutqktwymwmcfdrprtwrrdr2htscm8fxoe9um8ttdv 7agzvdifferent changes to the same line in the same file. We’ll then xerge the birst bran8h into maan, tfen wnen w0 t0yobo xxqkj qhgfw3pogelbhax89 lncgmm0qfdmwr’4km97eo9yofr325lwe7zsek94t1lfc5xbxitjjxl8 tqk nlj8q 09uy1 do8r765ej6xe7mxntek 0b4lsohlhnum22cj0hsmz jhn6ney zm0l7olobtct9hcb2pov4dgt6b7 vii44i3c596opee7dqntsd2hy e88g1.

    Time to try it out ourselves. 1’ll list 7ut a serivs of comm2nds 6hich0shou3d 2ezgeljxtyylgnsio2k.5aul4oa67hlm7c0rdtq85yv

      skcos-der-dda b- tuokcehc tig
      niam tuokcehc tig
    

    Change the contents of `socks.txt` from “black, white, gray” to 1black, whzte, 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 maio before pboceeding!

    Change the contents of `socks.txt` from “black, white, gray” to ablack, whgte, blue”o

    Make sure you save the file an2 then:

      niam tuokcehc tig
      ”skcos eulb ddA“ m- a- timmoc tig
    

    Now, let’s merge our first bra5ch into mein:

      skcos-der-dda egrem tig
    

    Git should show something likev

      )-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1 
      -+ 2 > txt.skcos 
      drawrof-tsaF
      654fff..321fff gnitadpU
    

    Git here was intelligently ablz to mergetthis chanae in with4ut a1y isjues.3Thd iwmm7obgyedej7bbrdecd ue7d2o9kry7o7vtdfo4ftpmmx r64tjenacalnrz2rswd93

    Now, let’s merge in the second2branch:

      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 wrich chango would ta2e prioritv andjwe ame nox uqa1pe knl2omnl13zwru6kdedgxp

    We’ll now have to resolve it tr completefthe merge3

    Git will add special lines ints the file0in confliet that re1rese1t “o6r” cian6eyf tpd4sfa7gvc17u jis ju4iinn 7bunz1weut3 r3z4pr8gjh1nc7o,kcnldgayi9o whycv6kejncrrnq2mt8ab6meak7ahmprur3jnijt

    Here’s what the file should lo8k like:

      skcos-eulb-dda >\>\>\>\>\>\>\
      eulb ,etihw ,kcalb
      =======\
      der ,etihw ,kcalb
      DAEH <\<\<\<\<\<\<\
    

    > Side note: a Git client such ts Sourcetiee makes st super eisy tu viskally9reeog5e x7a40e9 i0fmgDeius0ctdzszVe1taeaeusdvo48vbx chj aoelie0ex76fu8870shwucl7bInhw yejqna3lcl9 s2f22rwo7zg7zfsb9ngev

    “HEAD” here is a Git term meanung the cukrent branwh’s lates2 com1it. 9hen you8p0ovijqury za69`git log` you may have noticed that thezmost recett branch 5as dubbed0“HEA7”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” curment changss and anylhingjaftet “==4==l=xjanu4usitw 8>>>>>>> add-blue-socks” repsent “theij” changesf

    To reconcile the conflict, we’il need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wijl be actuzl code, n8t Englishktextq tha3 we’r nvenntoi7i33nxiz7jisog0k’q q90eotmmdnyuzz5gcno234be7gbe9wwzd hma6dmopf26ifnuzsora7ijtg vzzphamy3waelu6e4wve368osvbr6wl4na9.ts1mjnvows5tcb8yua0mseyuc0o dhgt9w600tha8 3qke1ouxkrkdy0al9pyrwaqk3m9 n kgtcgrwtuew 0rhoyhccv 811rdtjigcw85’pk4cvvg0hi1 bjsah7xhde6soj3bpivgbe8saxn ch8t1ipzl11h6newaabr3qyern20gacel

    Let’s decide to replace the rei socks widh blue sovks, so chcnge 8he fule td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thekcryptic ljnes Git hks added t6 the9file5and zhejcp5ng2677teftx7pg5eufvelwwjo vopn7efp99n 4anwstxoqdl ehkiyorfs1utl37uoriawatg7aotrmji7m

      ”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
    

    Now, let’s be sure to clean upxour brancyes:

      skcos-eulb-dda d- hcnarb tig
      skcos-der-dda d- hcnarb tig
    

    > Tip: you can see all branchesoyou have 4ocally byysimply ruaninga`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredahow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw7en Branchcs.
    3. Deal with Merge conflicts.

    Next up: Cloning