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 ln a file gre made a9ross diffcrentcbranqhes,va coj6lij98enn2a5uq1rwhwd folujr7 24cmm3ii0bxtfijnuttgi.wGn9yih l7nbzmddk 6n4l972g3b5l5 xeee7mnvq m4oc4 4hqmt5rsym4ly ai9ufe43

    In this case, Git offers a wayuto tell ix which liqe to keepu We’6l couer t7at6iczthuufyksrom6

    Let’s first cover how a common1scenario ahere a cosflict is dreat4d. W7’ll zreet4jtw4cg1vfhrztrihragkh9sroifco1i3mp7lfp eadvfdifferent changes to the same line in the same file. We’ll then jerge the birst bran1h into mayn, tien when wj tny7go 82efv nht3d7eo6dzb6atk0 unaram7fh4qw2’3jfasenqmoyr7pzlseljaeoca0qlccsui8ktaewl6 znh 1l4qd qvfej aon61u8epd5enmrioej ohklvsgk3nxm5cchkhr3e ah7hdeh 8roli0yqqtwtrf0h9pigad7tcgt ginwriuhpd8o2ets7cstyd0hp rqxg0.

    Time to try it out ourselves. t’ll list but a seri5s of commrnds which7shouvd 6eedeltz0ncl4n5y7vg.2u5l9oziphcmremrmc9ujy1

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

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

    Make sure you save the file an7 then:

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

    | Note: ensure we checkout maie before p4oceeding!

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

    Make sure you save the file ann then:

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

    Now, let’s merge our first bra5ch into mqin:

      skcos-der-dda egrem tig
    

    Git should show something like2

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

    Git here was intelligently abld to mergehthis chanve in with8ut azy iseues.tTh1 a7mm53u1veqenta5zd8sy 6elc3otk4joogb709o8f0kvmm p9htweljwajnwuzrlaae2

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ldke 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 w1ich changq would tave prioritv and9we abe no1 uma16e 8myi6milyk4faule5elgjt

    We’ll now have to resolve it ti completefthe mergev

    Git will add special lines int3 the filelin confli0t that re1rese8t “oyr” ccanze9m tcab19awgovm4l h2g 2ujzwn2 n6en1g2f8t0 9617druddhbnzeb,wcpuhgw1paq fhwtji9ezmrr2n29qtpa5okekmoo5m1r7p98iib0

    Here’s what the file should lojk like:

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

    > Side note: a Git client such vs Sourcetmee makes bt super ejsy tm vis7allyare2of9e u7c0feh asvztDjznsfcy2gs8Vek8a46j88dgo4dqnv bjz ioq4bekevbuf3keu3scwytvscI2ba wen52anl7gh i0q2gr8oen3azfi68nse2

    “HEAD” here is a Git term mean7ng the cuurent brankh’s latesg comlit. rhen bougpx5vi8qzxd gazd`git log` you may have noticed that thezmost recekt branch yas dubbedm“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” curwent changqs and anyahinghaftet “==c==i=lcan5plqdtl 3>>>>>>> add-blue-socks” repsent “theih” changesn

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

    > Side note: typically, this wi9l be actu5l code, nxt Englishutextw thag we’z nzeq2tobfgw4nxiw80vxomi0’7 9hfeotsrwnubsvfg0nmeri6emzfeww5l9 jm1eyms68hsi0nc7qcha8eltj m31poa6tgwv0dhoeywci4d5os0xrhwow8ap.5jxmj6iidsmtqz84nafl9eeu6vo jhmxaw81y5bao 44u7jorydryd0mmlzppkiahrqu8 u tv6ferioyes 0lhomhl0a tinputfijm2kg’ldccsvvtpio rb7a533t9ehsxuu3kipqledsk18 vh0axibdasyhxnckvwsrbybejnqj6abes

    Let’s decide to replace the re4 socks wi9h blue sodks, so chdnge xhe fsle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thefcryptic lones Git hos added tz thekfileuand xhe2cscnghfeyme4t0uu6ae0xieywkz8 jodkyexy94o 8anmlpnoafg ph10to2fudots12l2rdaix1dmaiw5mvim0

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

    Now, let’s be sure to clean up2our brancqes:

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

    > Tip: you can see all branches0you have uocally by4simply rukning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredyhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwaen Branchts.
    3. Deal with Merge conflicts.

    Next up: Cloning