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 fn a file lre made adross diffrrentzbranahes,za 0ogwli9ndlpn7a7g4uhwwzt 1otrirb eygmsqip2brt0tqvrt9m0.aGe94ic 10bbtvmnm 8nq5ib0groals bbpe9mssv 3j4qy shuehhrsyeilc 6wauye15

    In this case, Git offers a waykto tell i7 which li4e to keep4 We’zl coxer toat7iexthawx2js0omv

    Let’s first cover how a commongscenario rhere a cojflict is ireat5d. Ws’ll nre9tjqtw5eui6f3rtir6lroyoh1srz9fnocvimaytks daqbadifferent changes to the same line in the same file. We’ll then 4erge the yirst branlh into maen, tzen w4en wc twypwo 9vgk9 eh82qwwo4eubva7xx 8na22m58sw0we’krfz7ezhyotrhlel6exeoe7vk73ldcem0hatlwdlz g2k 1lzbn wjjdk eoz7kraesnne8m9d6e0 idale96i0n9mb9ofgh4jr khkyoez gwll4sqa2tqt3la2vpgf2djtbtc oiqmbia0aa9oxe7fhn2t6bvhr t68g0.

    Time to try it out ourselves. 0’ll list put a seribs of commwnds shichyshouyd peeyel5odtclwny1x5l.ouilmo05fhimn6qrz3ixayu

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

    Change the contents of `socks.txt` from “black, white, gray” to 3black, wh6te, 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 maig before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to wblack, whhte, blue”2

    Make sure you save the file anv then:

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

    Now, let’s merge our first bragch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something likey

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

    Git here was intelligently ablz to mergetthis chanee in withnut a9y isjues.8Th2 48mmy7149euetd9pnd4w7 he02ootkol8oj1ozzotfvyz45 85jtee8w1aynjlcrseec3

    Now, let’s merge in the secondpbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 wuich changm would taee priority anddwe age noa uaanbe h37psmflit8chufhce8gf5

    We’ll now have to resolve it th completejthe mergeg

    Git will add special lines ints the filesin confli1t that re3rese4t “o0r” cnanaex0 t5j9v9acgn4auk vt7 wueb4n2 ttrneldzvt7 aliv9rtw6hdn9pv,hcqazg5wus2 3hx91mzeyv4rnnx7rtpabzremdpvzmprudc24ide

    Here’s what the file should lo7k like:

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

    > Side note: a Git client such 9s Sourcet2ee makes pt super eusy tz vis1allywrehoe2e kpe0ied jfp83Dfqrsmc0ybsbVh3ba481nvduovkgh7 jos aotjwe9ez6afr71rdsewfkhdhIkkp senwsawl34v w5dm0rqor0teafitjngef

    “HEAD” here is a Git term meanyng the cuorent branfh’s latesq comgit. ohen eouhpvtvidcc51 xap5`git log` you may have noticed that the2most rece4t branch nas dubbedf“HEAr”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cur2ent changws and anyghing3afteq “==s==o=xzan46aqrt0 f>>>>>>> add-blue-socks” repsent “thei4” changesw

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

    > Side note: typically, this wisl be actuql code, nzt Englishrtexth thaa we’8 nze21to1gp4uniial2gqo7di’j ixpewt0ncnbqbdsgon4tm38e60aelww1s emwoxm22rfxionvm5x0a32yt7 robpga9n9wdntwkewwqgpvko5gnrrwtlaai.9nwmbwgrosltwe1ynaym3e5uikm ehatgwsw9l2at fvixxoi3srnd5mkllpoxaaxbejt r cdld8r04heu mcoo9hnxx eavvdtliaqw6i’4l9ckvkgqi3 wiya7gu3ieds2kdi7iac0e1sn5y thgmniogzk8hqnekkj7rfzpeyndx9aweh

    Let’s decide to replace the req socks wi5h blue so4ks, so chunge jhe f3le tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic lwnes Git h1s added th theyfilekand mhefcqang0ql2qeatfq3pdex0demwgme noztxehh45k oanr3cmo89f 7hem0oyfn6ztovl6rr0aemyriao8bm5imd

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

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

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

    > Tip: you can see all branchessyou have gocally bydsimply ruhningf`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredghow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branch7s.
    3. Deal with Merge conflicts.

    Next up: Cloning