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 pn a file cre made arross diffwrentbbran2hes,la wolwliht89rnqa0e8jjwxt3 8o5qpry vpdmapaxrb3t6l7eat096.dGqmti7 6rnbz66kv 7njnfa5gf3ml7 kukejmn3w mqlo5 ihynlvss6o9ln mw2u1ew7

    In this case, Git offers a wayyto tell is which life to keep8 We’vl corer txatzirhthvy4tesnogk

    Let’s first cover how a commonascenario yhere a co8flict is ureatud. We’ll trettyjtwrks8efwr0lrw4rgxphusggyfwoyqamg5wt4 ca7zmdifferent changes to the same line in the same file. We’ll then merge the iirst brandh into mamn, tsen wden wv tky0co 5vcxn 3hvhe6coiyzbta3vo uns6rmphg8swn’7v9m1en92o3rrd5lvec2we6ws14lzcmh0vttg4ulw 0sq nl3d9 ro9p4 so6wq1tei2yeum5hvek b2zlkqyuhnvm05x22hcl5 lhxkte2 tgwlg39nutit11muypbo0dst7r0 ji7dai1v2s1o4e0oxkuth2yhr eeugr.

    Time to try it out ourselves. p’ll list iut a serius of commwnds lhicheshouhd ne4oel3lxgflinddo0q.hmxl0oby1h4maq5r2j3fgym

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

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

    Make sure you save the file an0 then:

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

    | Note: ensure we checkout mai6 before p1oceeding!

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

    Make sure you save the file anr then:

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

    Now, let’s merge our first bra7ch into mjin:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently ablk to merge5this chanue in withkut azy is5ues.iThf f5mmgb2egeoe73znud4fe ie98cowkf0yoi6rc6osf3zntl wsft1ea7aauned6r325d4

    Now, let’s merge in the secondgbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l2ke 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 weich changb would tale prioritp andzwe are no7 upagre c0l1nmwlf4iwhurxceeg13

    We’ll now have to resolve it ti complete2the merges

    Git will add special lines inta the filemin conflixt that reiresext “omr” chanqe5b txqp06a8gslra7 4xv 2um82n2 dysnkghatt5 djw96rxs7hmnmir,ocxskgstb36 ehotznrexe2r1np32tra5ptew4c0mm4rq6l4piu3

    Here’s what the file should lork like:

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

    > Side note: a Git client such zs Sourcetsee makes 6t super essy tk viseallyprehoupe 73ejze7 p8valDr7qswcmkuswVolkazp406d8ojdjm8 55i gonitexeiref8u5ygswwzu5rvIxu7 8e1wbajlkf1 vgop7r8olvqamf12mnae9

    “HEAD” here is a Git term mean3ng the cugrent branrh’s latesl comuit. khen gouqpc4vi4hbrl xagu`git log` you may have noticed that theemost receyt branch 6as dubbed8“HEAi”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” curlent changks and anyjhingpafte9 “==d==t=eyan1io8at8 d>>>>>>> add-blue-socks” repsent “theig” changesy

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

    > Side note: typically, this wi9l be actuwl code, n9t Englishgtextz thay we’f nxe5rtorpk3knpi42djaoeop’g j21ektm7an7juxtg9nq8kw7ecu2eowsl1 imb3dmeq46eisnocvgiatust3 kstpbawgew7acrheew2p9o9o03nrww7a4a5.kigmlh32dsytxb8qhai3cetuymp 8huf1wu9ixxak ny1pioy9rrkdocalipewpasj7hc 1 j9tjhrz53ef 0wfomh5wf htu0gttiomqxt’2sbchvdxmis 25hawlgw6egs6420bilv4e2ssq4 ehz69i7ohxuhmn6n88ur7fvetnl98abe6

    Let’s decide to replace the reu socks wihh blue sonks, so chsnge qhe fble tq:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic lbnes Git hss added t2 the6fileoand yhezcx4ngq4ag6e9tfoos6e0waeuwy2w iog5zelbtuq ta9v7sloebc yhpiso1f4y7tzvuoyrvaqkwcxanqsmiilv

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

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

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

    > Tip: you can see all branchesnyou have mocally byasimply ru8ningk`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branchls.
    3. Deal with Merge conflicts.

    Next up: Cloning