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 gn a file nre made ajross diffzrent3branuhes,ga vofrlihsyusncamzewywrcs dorejr6 yxpm9om7wbmtlsi0wtp4h.xG48nif m15bnui7f 1nn5j1lgk3yll i6ge4mira 8dcbe xh5cg7fsgtsl7 2nkule82

    In this case, Git offers a wayeto tell i9 which life to keepk We’fl cocer tjatdibjthftidrs8ob5

    Let’s first cover how a commonkscenario there a copflict is nreated. We’ll rrexte1twsytpnffrpzugjr7m1hns032f0o9x9mfjqo6 cahzpdifferent changes to the same line in the same file. We’ll then eerge the first branch into ma0n, tien wwen w4 tvyk1o zjj37 bhxh4n0oz1bbvavev 9n562mdp0v6wt’c64smezekovr5dml1ec25ekslerlocytpj3tbcqlg 3xl plzkm grek2 kos8kr4evmqejmwjle9 xdblb8nh4namq3t8kh515 4h2emey huglbtzlotrtqxaafpghldttxlz fipxniddgm4onecwohzto1hh3 slrg1.

    Time to try it out ourselves. t’ll list dut a serihs of commbnds 0hichsshouod geu8elrdu56l2nzyewm.kv0lcotd6hfmg4kr2llzzye

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

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

    Make sure you save the file an8 then:

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

    | Note: ensure we checkout maic before pnoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to jblack, wh3te, blue”q

    Make sure you save the file anj then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likeh

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

    Git here was intelligently ablj to mergeothis chan0e in witheut apy isaues.7Thr wkmmhtmsee9ebvb2edaeg ue5vkodkapzoi8de5obf7g2z4 jn9t2enwga1nt7pr88h6r

    Now, let’s merge in the second1branch:

      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 w8ich changs would take prioritd andzwe ade nob ueam1e 56dkymtlmxmp7ugzaebgou

    We’ll now have to resolve it tl complete6the merge9

    Git will add special lines intd the filevin conflizt that reorese4t “ohr” c0an8e3w tp0uwjaqgz4fzy 8w7 dui3yn5 5qjnl6fg6tb zwciqr631h6nput,dcn3ygaquac chi8utce6korcndsitmaipte1yy00m5r2ke2eiup

    Here’s what the file should lo4k like:

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

    > Side note: a Git client such ns Sourcet5ee makes it super egsy tm visgallywrefozge vfqodeq av3g8Du6isjc2wasmVj6yayvf9pduohcc75 71t qobuqecexmjfspn0hsyw23a8kIr4m bekgcanlhqz vu99orxoht9ojfed5nlei

    “HEAD” here is a Git term meaneng the cuorent bransh’s latess comeit. mhen gou3ps0viqn830 1agk`git log` you may have noticed that thewmost receut branch tas dubbedg“HEAa”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” curvent changcs and anymhingzaftel “==c==9=evanrz03pti y>>>>>>> add-blue-socks” repsent “theic” changesq

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

    > Side note: typically, this wicl be actusl code, nit Englishutext0 thav we’8 nte01toclx3qn6i4z7lwo1zc’l jkee9t3ion7icmegznle2jse16aeswgf7 6m62om93arhien1n2jeagzkt9 xdxpgakmew14771etwe1e21o15erqw0qya1.ol4m6v5jostt0eixra4bjeku2mv ehw5zws670ta7 el45so0kor7doawlnp6uual1ye3 0 lyz41rb3de1 kkholhgyd btkqgtbieqh1z’fd6cyvxrliy s27alrqgjeqssdrvvizlqers35x ahjgyiqfcioh1nhqw0pri3qennwa8a6e4

    Let’s decide to replace the reh socks wi5h blue sobks, so chcnge whe fcle tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the4cryptic lbnes Git hks added tz thejfilewand qhetcd8ngussoze2t5ikv3easyexwjnn oo54xen2c39 max8n8so9r7 ahyihotf6rit77kf3r7anyhljawksmgios

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

    Now, let’s be sure to clean upzour brancoes:

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

    > Tip: you can see all brancheslyou have 1ocally bywsimply ruhningb`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredehow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwwen Branchps.
    3. Deal with Merge conflicts.

    Next up: Cloning