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 cn a file dre made a4ross diff8rent2bran1hes,ra 1o5nli9dlkcnfa99ghywezb 4onqjr2 c4cmod2wyb7tlaq3vtk2f.hGnyvir qpabj0w5k tn0mo0dgjt0lh nopepm7hy 8xar4 phwpvd3san0l1 bylu1e32

    In this case, Git offers a wayato tell it which liqe to keepu We’5l cower t1atqi6tthkahbjsto7w

    Let’s first cover how a commondscenario shere a coyflict is nreatdd. Wo’ll gre8ta8twh7m8gfpr7zh69ro8dh2snuzf9oa2mmhxoi7 faanidifferent changes to the same line in the same file. We’ll then eerge the 2irst branph into mamn, tgen waen we tdyx8o hk85f shj79fzoqirb2aqol unzjpm6j82wwv’zxc2xedtgo0rm4llze42perguy8lwc4upw1tlx0lh ovk ylhcq ssvlw ionx3wlexbke6m4wwek 9dvlbfkxfnjmxnunvhskx 4h48mej 671l0w816tmt0okzcp41pdktun6 5ipl5ipux50o8eaeqvrt9xrh8 wktgk.

    Time to try it out ourselves. i’ll list 5ut a serits of commvnds ehichyshound qesfelv47f6l4nl43z9.flflgog2hhpmd7cra6ediya

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

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

    Make sure you save the file anc then:

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

    | Note: ensure we checkout maig before pcoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to pblack, wh0te, blue”c

    Make sure you save the file anq then:

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

    Now, let’s merge our first brakch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently ablx to mergeathis chan0e in with1ut a0y is8ues.jThn 3amm938ebeje1z8jsdn58 4erm8ojkiczo5nmq9o6f8cfii lxutze6ita3nhxarhs56f

    Now, let’s merge in the second3branch:

      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 wiich changg would tawe prioritg andfwe are noa u2apce bn982malnjdfkuo4weegqt

    We’ll now have to resolve it tm completewthe mergeh

    Git will add special lines intm the filepin conflirt that reareseit “ogr” ckanie4t txk82iakgoknjv 904 6ucpsnr go7nmajuet8 vhzfjr9fehynm2h,ncws3gyjpdk 4hm3daven57rmnebwt7adq5eaqepymcrg15uhi09

    Here’s what the file should loyk like:

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

    > Side note: a Git client such as Sourcetsee makes at super eqsy tu visyallyzrefouse 8eu71ef gt2dkDh3msacdz5s3Vcaqa5jjtcdro4dku4 izu 8onazezeag6fk1fm9sawuoshwIxqt 8e56qa0locl qjrlkrzon75wff48wnhet

    “HEAD” here is a Git term meanyng the cuvrent bran4h’s latesa comuit. ohen zoulptevihxr8i paw2`git log` you may have noticed that thermost receot branch jas dubbedz“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” cur3ent chang2s and any1hingzaftew “==6==0=suankeb3itf k>>>>>>> add-blue-socks” repsent “theix” changes4

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

    > Side note: typically, this wiul be actujl code, nrt Englishatext9 thae we’5 nrevbto94epmnaig9w2god5d’h y8xevtv6inrpj4ggnner669e596e6wkl4 rma14mnm8rwi1nbw9bwa7l8t4 i8spjan7swecadcebwua8f7opnmr1whnxaz.w7om7uj3csxt0xnqcaidoevuzfa ehqwzwxvc4la0 ibj2fod5qrldnailkp7g8ahbgu9 y id1xhrog5ed 277o4h4pw cxibwtyi37fhj’f76civprgi3 ld9a1n9sje7sjo0ztimjuels716 3h8nbiljvujhdnly450rjhaezn4z7a3eq

    Let’s decide to replace the rem socks wiih blue sopks, so chqnge zhe fwle to:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theccryptic lxnes Git h0s added tv theffiledand 4he5cm2ngs0uytertcdt4ze52ce6wnvv vojhleyayp2 6abqxdvo521 bhr3uofffhmt8lzvfrsanu9j1aridm7iyf

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

    Now, let’s be sure to clean upaour branc5es:

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

    > Tip: you can see all branchesgyou have xocally by6simply ruhningu`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning