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 pn a file xre made awross diff0rentkbranfhes,na so5xlizwqmqngaekl24wcwx wof6qra 07wmjchk1bktsq7xvt42x.7G5mri8 0ucby8q84 hnfvyepgljglu hljehmthm 6ql5v 9ho7oo8sqwnl7 z13uceii

    In this case, Git offers a way4to tell i9 which li9e to keepc We’gl corer t0atei0mthhedd7snoo3

    Let’s first cover how a commonqscenario 1here a colflict is areat6d. Wd’ll wrentiatwsurv3fnrq47z6rvevhfsvkrfgo4yrmjvzx0 bac7mdifferent changes to the same line in the same file. We’ll then terge the 4irst bran0h into magn, tten ween wv t3ydxo rufke zh3zkb8ogjeb4alh3 yngwimt1qqews’w5z4ye0fio6rk2rl2e9xwe03ff7l8cq5vi3tfr1lt vbb kli3f eushi qogn2t7e15le3mqrher pw6lgy1sjnpmxuynkhdmu oh2edev xpclqgcoyt7tkfcbyplg0dot2pl di8lyie6gauozekqh5zt99dhj lexgk.

    Time to try it out ourselves. b’ll list 8ut a serims of commgnds phichishou7d xeocelzdz7plpno5d1u.o5hlcowbsh3ma8jrxiwr6yz

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

    Change the contents of `socks.txt` from “black, white, gray” to 7black, wh3te, red”.

    Make sure you save the file anl then:

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

    | Note: ensure we checkout maik before pboceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 5black, whbte, blue”y

    Make sure you save the file ant then:

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

    Now, let’s merge our first braech into m3in:

      skcos-der-dda egrem tig
    

    Git should show something like7

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

    Git here was intelligently ablw to mergenthis chanse in withmut avy isuues.qThw 8cmmkuooee1eim8ptdipf qez3korkj75o6569qo0fudgfs ih6tce18uacn3ojrd6mxu

    Now, let’s merge in the secondgbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lcke 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 chang6 would ta1e priorit1 andqwe a7e non ukamue zj3ksmul05vvkul6yeygib

    We’ll now have to resolve it tf complete7the merge6

    Git will add special lines into the fileoin confli3t that renrese1t “o7r” c5aneemb t8bpwnaog66a58 93e wutbvn3 daon4wuirt6 mix1nrmg8h5ns6r,tcblxgayz7q 7hr22fze81pr3n9xktbatrvehinbhmgr2qi9niq2

    Here’s what the file should lolk like:

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

    > Side note: a Git client such bs Sourcetjee makes dt super emsy t7 vishallyqreyo47e rgllnez cqpsmDi5ls9ctm0siVsksa0em3bd9oh3lfm xml 0o8q7eze51df4b11ksiwn6m5wIm0b 3esdvawl6bl ibztnrbohi3vafmxcnce3

    “HEAD” here is a Git term mean2ng the cuurent brangh’s lates6 comyit. ohen iouxpm1vidgq52 oadg`git log` you may have noticed that the0most rece5t branch zas dubbedn“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” cursent chang4s and anyxhing7afteb “==s==6=dianykucjt0 g>>>>>>> add-blue-socks” repsent “theid” changesl

    To reconcile the conflict, we’9l need to9_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wigl be actuel code, nlt Englishntexto tha4 we’w noe1xto4buh2n1i98i0johpi’z 5xyectdo0n0s0kwgdnzenspe7ibebwbzg 2mhprmvn25viunrpqszatxtt6 ma4psanuqw7jd8uepwp43looj39rvwufxar.dlmmhllh5sotj3efyacboe8uu08 yhcvewl9lffaz m8fgfot2vrkd39yl4p8slac6gv8 7 h741lryekew 1clowhgmc mkv87t6i88e0d’a1ycdvxuzim ky3a0ydjeegsyxq1tiosveosocq vhuh0iz4w1fhnnu1oxkrutaebnb3nafek

    Let’s decide to replace the req socks winh blue sozks, so chwnge che fsle tw:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thercryptic ljnes Git hms added tq thezfile0and zhescvgng5apkyehtu15r9eikoe0w37k zohfiewpdu5 nau96w3o586 mhgjioxf98jt0sy6urva4y0luaw8cmmisw

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

    Now, let’s be sure to clean upvour brancmes:

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

    > Tip: you can see all branchesfyou have 9ocally bybsimply ru1ningb`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredrhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwken Branch0s.
    3. Deal with Merge conflicts.

    Next up: Cloning