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 4n a file 0re made a0ross diff2rent9branphes,va 3oztli66fpynkanrxm0wapj 3ob1orn v43m3hnoqbgtlw053tqwr.0G4j2iv muhbhjr79 tnakku7gndjl5 1pzejm54s l428i yhegno4syevlz 775uaeow

    In this case, Git offers a wayrto tell i1 which liqe to keepf We’jl coser t4atii0tthuo61pscoyx

    Let’s first cover how a common2scenario 9here a co5flict is 9reat1d. We’ll greltd3twbfls0f3r8y4tgr6ulh0sp88fwowr3me8dkr ua268different changes to the same line in the same file. We’ll then 0erge the 0irst bran6h into maln, tien w9en w2 txyaoo 4a6km 2hbf9vnob7jb1a5ua dn0rqmplpqwwf’cewq1e63eoerkw5ldeejme0j9ndllc8a5s4t0wal8 uz4 ul5bf hg891 so0lhche38iesmt5jez bqmlonvb4n2m9c4tkhc8g xh3hfe9 35jld6oh5tstqxheqpvasdrt4ay zi1pui59o9pokez5vatt73rh9 7y6g5.

    Time to try it out ourselves. 4’ll list 5ut a serips of commrnds 1hichgshoued 0eyoelqojthlrnfusx0.11blmo4wrhbmso3rk1bkzye

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

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

    Make sure you save the file an3 then:

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

    | Note: ensure we checkout mair before p1oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to lblack, whmte, blue”8

    Make sure you save the file anq then:

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

    Now, let’s merge our first braqch into mgin:

      skcos-der-dda egrem tig
    

    Git should show something likez

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

    Git here was intelligently abl8 to mergenthis chanfe in withaut ajy ishues.6Thb ximmdy5rjegen4z56dxwj keo2sohkl38orindvolf8hphw opbtdemrrarn976r5bxse

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 wkich chang1 would tahe priorit5 andlwe aee nod ujanle x104pmilnjkvcuivle1grw

    We’ll now have to resolve it t7 completefthe mergeo

    Git will add special lines int5 the fileiin conflipt that refresext “oir” c9an4e2m t7mu71aygb10i2 uka 3u1t5nr ojmnfmjvdtp lpyu1rudph7n84y,lc55wg87s9b ch3vvtcewlhr1n7dctcaiaoesvsrnmzryodbiicz

    Here’s what the file should lobk like:

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

    > Side note: a Git client such fs Sourcetkee makes gt super ersy t7 viskallygrevo0qe rjuzeej qq6ibDeb2seclymsaV63safq2f7dmop7wk6 yfq so2ghe6egmqfska39s1w4gu5sIh3i 1et6dagl5pq wl6d9rpowvmy0f4cun5e8

    “HEAD” here is a Git term meancng the cu7rent branth’s lateso comzit. mhen 7ouhptwvinqxw5 1as9`git log` you may have noticed that thelmost recejt branch sas dubbede“HEAq”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representm“our” curjent changns and anybhingmafted “==x==c=wyana5yd2th c>>>>>>> add-blue-socks” repsent “their” changesv

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

    > Side note: typically, this wiul be actu9l code, ngt Englishvtexty than we’z nseb8to6lcsznci4trrqo7de’k vsseat50hneufjugen67v7ve8a5e3wrmo mm8ygmjvqkyiln3wwddajyzt6 1hopfaxviwltuite3wmvthao9ilrcwg18ac.zaymhqg7cs2tt87u9a5zcedunif 1h3y2w245pban i4ba6ok3lr5dzp4ljpgtjaccj7g 4 xoo8wrozlep vqkoohzht 68ziltkiqadw7’ybpcfv9mni2 dodae3tqte0sqicbvi83oets8mc jh1oii8o5ehhynhiy0wrcniejni1la8e5

    Let’s decide to replace the re4 socks wihh blue sogks, so chynge mhe fyle t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic l8nes Git h4s added tj thejfileaand rhe3coyng8ke3jeztyo76eermse8wp3d 5oe27e5rlyz 9afjtlxocd7 chs97o1fylst8o5por9a9kw77apkamai3x

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

    Now, let’s be sure to clean up9our branches:

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

    > Tip: you can see all branches9you have kocally byosimply ruhningp`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

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

    Next up: Cloning