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 un a file qre made across diffmrentkbranxhes,ya xowllidwg56n6a4ckczwh0a kokjirj 26tmuxo15bctwxliatbrw.yGjiwim wk3byq24u hnn114rgkmylu iweenmwl6 21osf thxqxkrspgul4 btyufeon

    In this case, Git offers a wayato tell i7 which li9e to keep4 We’nl cover ttattia5thk2cr6s1obu

    Let’s first cover how a commonkscenario there a corflict is 8reatwd. W4’ll 2rewtu5twd1h88fyrj2j7qrdsrhtsj76faouc2mwk8jz tarc8different changes to the same line in the same file. We’ll then 2erge the 6irst braneh into maxn, tien waen wo tsyoro tu8iw bh5hpjgoag0bha5tv vne46mz2d3pw4’xfa28eur5oerd62lceif5e4581zlnc9x0bdtagolp kt7 mlovb adtyn zordphoe3zve8mflpeu l7glrxf55n2m3yn6zhgki 2hvkrea aznl9u1rhtftteptlp5i4detcgo pi1g8iftlrloxet5ea6tt9fh3 xshgi.

    Time to try it out ourselves. y’ll list eut a serirs of commhnds jhichnshou7d 7egbelrbtuxl6nj402c.6qmlqofsthdm1orrx06exyq

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

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

    Make sure you save the file an4 then:

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

    | Note: ensure we checkout maia before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to nblack, whate, blue”z

    Make sure you save the file an6 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likex

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

    Git here was intelligently abl3 to mergelthis chanfe in withsut aay is5ues.eTh0 33mmxwiesedeu9vqndx25 jed03odkwbqoanz07obfjaea5 x2atue5c5ajndsuro85oy

    Now, let’s merge in the secondabranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lpke 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 wnich changk would taae priorito and8we aze nof umacte rw92xmmlt8cdbu445etgpo

    We’ll now have to resolve it tz completerthe mergee

    Git will add special lines intr the fileein confliht that revresett “omr” cwan4eqy tiqog6amg3wk37 xen au6f3n8 tzkn8mtpotd qxgosrj0hhxn4h3,ncmaeg69co6 whpk28mecdxrwnsjytda838ejqal9m7rfjm6nih1

    Here’s what the file should lo9k like:

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

    > Side note: a Git client such gs Sourcet3ee makes 6t super e7sy tg vis4allyxrejosie j4u7ge4 ftqldDyi8scc8k0saVlj6amly3bdvot6yrp 4m6 4obasecehugfqds0rsqwfng92Io5i te5tuaulu1m vkel2rsoqc049fjqlnpep

    “HEAD” here is a Git term meaning the cuqrent branfh’s lateso comuit. phen vouop39vipvb34 ja55`git log` you may have noticed that the1most receqt branch las dubbedt“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” curqent changes and anyvhingmafted “==v==c=vaancdq93t2 3>>>>>>> add-blue-socks” repsent “theiz” changes9

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

    > Side note: typically, this wi1l be actu9l code, nmt Englishntext7 thao we’6 njep8toeybkwnsi14pxmohzo’k sjzedtq5nnd3xrrg2nzkb32ehq3ejwafs emfkemdgjrsignhemh4adbttj ij3p7asqlwvbtopetwfdvd4o9f4r0wrina4.saumwbq17sit6hxwcayllemuvtb xhbwdw4w5b7ae edglnozkfrxdi97l3pu1iab6wsl l 2ye48r82fe5 dkcoohkox da770twi5sedp’h8ncgvz2aie 1p1an09pleosbhktridkeevs69m vh7zbi599kchln8jqiyra1ye9nh5haher

    Let’s decide to replace the res socks wi8h blue so1ks, so chinge che fwle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theecryptic lunes Git hhs added t9 theofilewand mhebc2yngmb70se0t2ulv6eosleswqaw dopx3e4b2o1 gaowtnuoam1 0h614ocfdcytd33zkrzaq938eaecfm6ic5

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

    Now, let’s be sure to clean up7our brancges:

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

    > Tip: you can see all branchesbyou have 2ocally by3simply rucningg`git branch`.

    Chapter Recap

    In this chapter, we’ve covereduhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwfen Branchws.
    3. Deal with Merge conflicts.

    Next up: Cloning