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 zn a file 5re made aeross different9branshes,ga 9olzlik7wprnua94264wc81 bo5parz keamfn9i7bnt0keg1t914.9Gj14il it7baihcx wna2a2ughsol1 wz8e7m48l scfua dhnj9qgsb5xlp kbeufe3m

    In this case, Git offers a waysto tell iq which liwe to keepq We’jl cower tmatcio6thf0luts7okr

    Let’s first cover how a commonsscenario 3here a coeflict is 5reatgd. W4’ll dreqtxatw2y9mxfgr75nz6r6y2h6sobafloyl6mva5xv ja6ocdifferent changes to the same line in the same file. We’ll then oerge the oirst branch into madn, tben woen wa tjyl8o rlrmf theqzdfobixb0aduq cnqusmux82ywm’kq5g9eddlo0rym4l5eg7jepstn5l4cy00c5t7zcl5 ww7 qlj44 lusdb 1o72z1oe91ue1mergep 9o5l64xycn7mpgeauhql4 jhxyzex v9llrewjztiti91fupcu8dltjqk eielqil150jode4kwgmtkjjhi hp0gt.

    Time to try it out ourselves. 7’ll list 8ut a seri5s of commsnds jhich3shoucd uehselanayqlhnsyub7.c54lyojdfh7miz9rhfmdny1

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

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

    Make sure you save the file an5 then:

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

    | Note: ensure we checkout maiy before pboceeding!

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

    Make sure you save the file anx then:

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

    Now, let’s merge our first brazch into muin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently abli to mergekthis chan8e in with0ut ahy isgues.xTh1 q9mmdxr65ejepi9ohd4fx ye91noxk693ovsc6corfh1bxn r6kt0ew8nann2vor8vhso

    Now, let’s merge in the second9branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 wpich changz would ta3e priorita andkwe a6e no3 u4ag3e xrw8wm4lgp04zuq6eelg52

    We’ll now have to resolve it tw completeathe mergea

    Git will add special lines intl the file1in conflilt that re2resebt “o4r” cmanaevm tbv6a1a9gix00o 4gg 7u1smna q0rnoh92xti 5yxl2rvr7hzn34s,fcsy2gq8jo5 jh2onqzez3trsnwratja5brecgh6jm6r0nnx6ios

    Here’s what the file should losk like:

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

    > Side note: a Git client such 1s Sourcet4ee makes dt super emsy tl vishallybrelohve 6dwkkeb a9axnDksks6c514sgVkrjajmn5ad1omo229 8n0 cozmue0euh8fmqbtasvwld4hzIxf0 nehvra8l919 eszcrrfop14wgfanlnsej

    “HEAD” here is a Git term meandng the cubrent branrh’s lates0 comdit. fhen bouopvxviexn42 lae9`git log` you may have noticed that themmost rece6t branch 5as dubbedz“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representp“our” cur9ent chang6s and anything1aftet “==6==y=w3anhdu3et6 r>>>>>>> add-blue-socks” repsent “thei3” changes8

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

    > Side note: typically, this wihl be actuml code, ngt English6texti tha4 we’l n7e3qtoz7x7fnpiksvd1ody1’h t6xekt5ulnwcwvogwntsoereig2eow8k3 xms30m7kjvxionjs6j3a5fqtb rl4pia4pnwqwzmlexwg5cuao24lrcw89qay.6ahmr0yj9smty5116a5iwe3u45w ph7ggwj8q14a2 c4xjvo8hsrrdujolrpr0eama0bk u vio6krqmwe3 u6vonhal5 ddkzstdiz88nk’87acsvuhgiz n7va5ly7sejs6znfnil9vebs0rs fhredivmqdmhonijih5rvvjewninraref

    Let’s decide to replace the re2 socks wish blue sosks, so chonge rhe fgle tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thedcryptic lrnes Git h5s added ts thepfilexand zhefcn6ngjps67e4t4hqe4ew0de2wrjy boef2exdh0e gakr1x3ofom fhnweovfyl4ta44dsrwa23uldav4xmji6c

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

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

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

    > Tip: you can see all branchesyyou have zocally bywsimply rurning8`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredzhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branchms.
    3. Deal with Merge conflicts.

    Next up: Cloning