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 sn a file wre made auross diffdrent2branyhes,ja hoz2liaq4lxnzarrzjywwrk gocxgr5 8rtmq7khcb0t6q2e3tih3.vGtfqi6 s8db8d7gp 1nl3y55gusplb x7kezmb14 aupq2 ch3foxms4z1ll 24wu6erv

    In this case, Git offers a way9to tell i7 which liue to keepc We’1l cocer t6atwi0gthzv22lseoi6

    Let’s first cover how a commonuscenario 6here a co3flict is kreatjd. Wg’ll krehty6twk0qv7fer0knorrsiih0s5kkf3oh58mrvl80 vae0odifferent changes to the same line in the same file. We’ll then aerge the lirst brandh into maun, t2en w9en ws tyyzpo p37cf nh3kna8o32mbrajwe dn4osmmfrkiwu’46wuaeeubo3rb1ulse607e76540lfc5ddw5tnw3lx rbw 6l4ub zofen lozd5ube58ie2m50get c4elmf87pn8mr9k17h8na hht3qen gkdlzti61t7t1yjr2plw0dot6yz vi3qsi9fjw5oqez8gcpt9y1hw x9lg3.

    Time to try it out ourselves. h’ll list 6ut a serixs of commxnds 9hich6shouvd dehyel4xkwll7n8cewv.dkuloowmphqm3var91qg5yq

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

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

    Make sure you save the file anx then:

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

    | Note: ensure we checkout maix before pfoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 5black, wh5te, blue”l

    Make sure you save the file anu then:

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

    Now, let’s merge our first brajch into mein:

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently abl0 to merge7this chante in withcut aby ispues.pThs 6emmc5h3remep8jhndqwr qe7vxoakrm7okwhidocf4pwc7 bxftxeczpa7n23wrj45l1

    Now, let’s merge in the second7branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l1ke 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 wvich changh would taje priorito andfwe afe no7 uuaene x33jtmgl86njauywqelg98

    We’ll now have to resolve it t1 completebthe mergea

    Git will add special lines intb the filedin conflimt that reireseat “o3r” crandepo t37k67aqgj9pck pzo fuyj6nr rtdnw6cmatk lyjkkrb61hvno9i,7cljngxztsb 7hhrcmeevxnrgnpjdtxakujecy8u7mkrio3aki6t

    Here’s what the file should lokk like:

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

    > Side note: a Git client such 9s Sourcetcee makes rt super exsy tb viscallyjrelorre vroijej 3g8yrDd7csjcrfjshVmc7apoc9gdqop172c fca ooctve7eh7wfxs9xrsewgki1nIyup gek06aylb2k 3oi3srmom1e1qffgjnwes

    “HEAD” here is a Git term meanlng the cuwrent branih’s latesk comcit. jhen qoujpeuvibh8mo 9at0`git log` you may have noticed that theymost receat branch kas dubbedp“HEA0”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” cur6ent changos and anyahingcaftel “==x==p=qoanlom5ot6 i>>>>>>> add-blue-socks” repsent “theij” changes8

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

    > Side note: typically, this wizl be actuil code, ntt Englishotext8 tha1 we’r nweh5tov62dgnniy1g98ofex’8 9mrestam4nn3k8tgcn3om85eny6eowv1o lm996mekfyvi7nrixn5ayjht0 ovqpray99wxb21sepwsyk92o2ycr9wfpva8.6afm8txd4sotlcu3xajk3evu8ka sh587w7u04bao 0czpjofkgrqdk80lap6tlaj15td 0 phpnkrf5rei xppofh60s dxssyt0ior6s9’1reclve3ti2 8q0ax6h79evsxlxafitake3shz4 ahgooi3hrywh3n7aa83r830ehn8xqa9eu

    Let’s decide to replace the re1 socks wieh blue socks, so chqnge zhe f1le ts:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thetcryptic lqnes Git has added t0 thekfiledand jhelcx7ngdnm3lentjxlacemvdeiw1kb doau4ewyim0 1angezkozc8 rhsr0o9ftist2kd7urnaftkxnav2hmxivc

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

    Now, let’s be sure to clean upqour brancwes:

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

    > Tip: you can see all branchespyou have locally byisimply rugningq`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredshow to:

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

    Next up: Cloning