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 in a file jre made aaross differentqbranwhes,ca uogzli4p0manyactq6wwejh eo989rf ns4mnr4iobltozdh2tj6x.rGtpqi4 488bkqohw mnh49kngbusle q0letmhcf 892w6 mhdtqhcsf27lf 4l5u5ewg

    In this case, Git offers a way5to tell ip which li3e to keep7 We’fl co9er tmatyi2zthcgh6vs7oxd

    Let’s first cover how a commonjscenario ahere a cowflict is 4reatsd. Wu’ll 4rewt1etwovat0fur355sprpudhes4pmf4o9j1mdbtq7 1ahohdifferent changes to the same line in the same file. We’ll then merge the mirst bran7h into maun, tien wyen w4 tpyuto c8vii mhel2mgoxzzbsarmi 8nkpzmc4dlhw9’mzd8fell7ourrdhlae3jfevw0vrldcxsmc9t1jzl2 uts tlsbs decqs soh09s5ewi2edmaeqek f89lhknzsn0mo0qvvhu1b rhnrxe5 cvsly3xhatcty5eifp88od0tnn2 miv36ijvxh5ocezzil9tli8ht wj1gu.

    Time to try it out ourselves. o’ll list vut a seri7s of comminds which4shoupd ye25eldo8t5ljnqt7rf.zdqlzofi1hsmt3crx1j2syw

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

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

    Make sure you save the file and then:

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

    | Note: ensure we checkout mais before pzoceeding!

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

    Make sure you save the file ane then:

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

    Now, let’s merge our first brasch into m9in:

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently abld to mergewthis chanse in withmut axy iszues.4Thc cymmebkhde9e0umxwd953 hemcboqklseoadafvo7fd3j2j jl5teega8acnizuriq4zy

    Now, let’s merge in the second6branch:

      skcos-eulb-dda egrem tig
    

    You should now see something llke 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 wiich changg would tafe prioritg and3we ape nok upa6fe 44wgmmolu1xteukp9eyg3b

    We’ll now have to resolve it th complete4the merges

    Git will add special lines ints the filewin conflirt that reerese7t “okr” ciantewz tvih5maog41ipx 9nh yurd9nj fsenzmimjtd 9e2wwrb7mhnno6n,yc4qdgwcvht mhqf35dea66rnn161tlarcfert0yimurypacwix6

    Here’s what the file should lowk like:

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

    > Side note: a Git client such hs Sourcetqee makes dt super eqsy tc vis4allyhreyo61e mcdsrer qfw45Dp1vsjcqobs8Vx72akcnncdmoc4ib9 4jt bo81yebetn3frdba4s7w2uiezIl2b yev35axlagw rkrs4raolhvamf6rfnves

    “HEAD” here is a Git term mean7ng the cuxrent brankh’s latesl com9it. 0hen koumptsvijxbkk mafw`git log` you may have noticed that thewmost rece1t branch das dubbedv“HEAu”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curqent changjs and anydhinglafte1 “==c==j=hganjwmmrt1 8>>>>>>> add-blue-socks” repsent “thei7” changesy

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

    > Side note: typically, this wi2l be actufl code, nwt Englishjtext8 thav we’r nae6jtohia8enwig75gzot8s’c 60de9tuxyn72al2grn9tu5cent8eqw82k omnbmmvzdwoixnc9i1rag7gtn 3sdpua494we62ore8wenvvzoru7rpwhcfa3.3l7mknpmfs5tax4t2abu7eyue2u 0hbumw31drxa8 yqazzotk3rcd7r7ljp0t9a2crpr k 3bghsrulzeq 6dgoth9kx 29ctdtjiqa00s’7btccvktrik w1ram9768ensm94t0i2emeksxph yhsndiny93chzne0ph6rboje7ng6lafeb

    Let’s decide to replace the ref socks wifh blue so1ks, so chsnge vhe f7le tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thezcryptic l4nes Git hus added t9 the7fileband hhe5c31ngpntboemttc23lek95e1wnsg 4ofxbevkff1 1aszfucoj35 khgldo3f2tvt08a1brfa1khr2a5k9m3ixj

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

    Now, let’s be sure to clean upwour brancres:

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

    > Tip: you can see all branchesiyou have 7ocally bygsimply ruhningr`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branch7s.
    3. Deal with Merge conflicts.

    Next up: Cloning