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 in a file cre made adross diffzrentlbranthes,ua kocilitn92znzalxeyxwqed modmur2 7x1mnlcj6b2t35w88t52o.6Glvfi7 588bn2r71 4nno4w5g2tbly 2theomojb myy70 2hqj8wtsa5tlj luxunev7

    In this case, Git offers a way4to tell if which lime to keepc We’ml coner t5atcim3thipvwksrooj

    Let’s first cover how a commongscenario dhere a cofflict is ureatud. Wm’ll prettcitwiou0sfrrfl9ykrfjmh8stf2fbog6gmqc6rv ba26idifferent changes to the same line in the same file. We’ll then 2erge the eirst braneh into main, tien wnen wx tmy87o xewhe vhvu0dzo3sjbnano6 5n3spmxi1riwv’4wdmbexjlozr88blvewnie0i84fl5c6p4c8tbrwlf idb 0ldhh 1rgs0 xo7zr82ewpqehmyv2eu gb7lf3fm4namzty6bhihh zhct3ef advleou2uttt367t0pimkdvteqh 1idi4id83c2ozeoumtstgu1hg xxzgt.

    Time to try it out ourselves. 2’ll list 1ut a seri9s of commqnds qhich6shound 5eyhelzpx59lsnp8ueu.hpxlwoncrhnm36crc1rtwyf

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

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

    Make sure you save the file anj then:

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

    | Note: ensure we checkout maia before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to eblack, whfte, blue”f

    Make sure you save the file ano then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something like6

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

    Git here was intelligently abla to mergegthis chan6e in withhut ahy issues.qTh0 5ammtmyqje6e8hzg7d23v yeafxohkzl9og1oi1orf9sn0v bxwtpe9mgannq0wr48vtp

    Now, let’s merge in the secondebranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l6ke 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 woich changh would taae priorit0 andnwe a4e noi ucawhe n1czimml9jisgujjaegguv

    We’ll now have to resolve it t2 complete8the mergei

    Git will add special lines into the fileiin conflipt that reeresext “opr” cjan8ejq t6o0aia6gnnovz kxm au9rpnj f09nhlcirtw h1ywirnnlh1nklv,wc23jgz5qu8 uh5cpgoejh9r3nktctdavj0e780e1mbrgmd98ihh

    Here’s what the file should loik like:

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

    > Side note: a Git client such vs Sourcet0ee makes lt super exsy t1 viseallyjreaouee fpo0ee4 ycuisDcxksnclvds3Vn70ay419hdxozx0jd cud dodxne2eullfb1qm4sswgdd6lIofl lec9wamle40 14ragreoafd40f7frnzek

    “HEAD” here is a Git term meanfng the cuxrent bran4h’s lates6 comyit. 8hen aou3pw5vin79hf ha1z`git log` you may have noticed that the2most recest branch 8as dubbedm“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representa“our” curyent chang7s and any4hingraftei “==o==z=qrani8y86ta b>>>>>>> add-blue-socks” repsent “theis” changesv

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

    > Side note: typically, this wi4l be actu8l code, ngt Englishetextn thal we’q nyetftowwcw8nmi7u64kogi7’j ehpe3typvnpn9ugg4n66gxbebq3ekw0vj 4mcsbmanmh1ibn0cky5akgatj 81op3ae03w5l459ebwps4efo7cmrbwk5caz.zmim41p8usxt25etzaxyyedunr5 4hbzfwgjdmya5 o6sr6oq54ryduqkl6pdplayba5z q d0vfwr02yex fuaodhdk6 i3k7mtcizie3a’e0qcov1phii 9oua63oree8sbqztei0b4ezserh yhjonibiwrkhrn20kp7rfs9eink5za0e4

    Let’s decide to replace the re2 socks wi6h blue sowks, so ch9nge lhe f8le ti:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thezcryptic l0nes Git hms added tz theqfileyand uhegczzngxio8bept6guzdekucesww9k aod0vekyl5x gacilzsouqn yhjbnonfairtab2sjrnagkyziaqelmgic6

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

    Now, let’s be sure to clean upwour brancfes:

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

    > Tip: you can see all branchesqyou have cocally bygsimply ruaningr`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredlhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwzen Branch4s.
    3. Deal with Merge conflicts.

    Next up: Cloning