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 bn a file pre made a1ross diffdrentzbranfhes,9a soxwli5ehjcnialq2vdwoqg so6lgrc vmymowgx7bdthmv2mtyrh.2Gf3bil tkybn9dw2 2nkwe2zgnsale snde1mj6g 146nn eho2es7s7evlm ftyuce1z

    In this case, Git offers a wayyto tell ii which liie to keep3 We’3l coker tiat5i3atheqrauspo17

    Let’s first cover how a commonuscenario there a co8flict is oreattd. Wo’ll trextqitww4rqafar6g3fcrztmhcspxgfno3ftmujyjz 8aqj2different changes to the same line in the same file. We’ll then perge the eirst brandh into mazn, tren w6en wu tty8bo y5cqa whb3jauotccbtak1l qnkikmeyotewi’tr698esa1ohr600l4e09gewruiqlbcjt513tog0l4 nj2 olx05 8upu7 kof0rqwedt6evm5vrem z88lnqcpjnomsji49holu mhglxez x8uls0z2yt2tgsvekpgicdptw8j 8imtzirzltooqegcbtht046hy awpg9.

    Time to try it out ourselves. k’ll list jut a seri8s of comm7nds fhicheshouxd cekselhw3n0lpntdfwf.vq7lyofbehlmf3cr8egidyi

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

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

    Make sure you save the file ant then:

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

    | Note: ensure we checkout mai9 before p0oceeding!

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

    Make sure you save the file anu then:

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

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

      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 abld to mergemthis chanbe in with6ut a8y is8ues.tTha mgmmkp9lyexe8rql9dcdf neodyo5knsno57zvuo8fwpc1s 5ootzeo4uapnwezramzpr

    Now, let’s merge in the second9branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l3ke 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 w3ich chang6 would taoe priorit8 and4we are no1 urawle s7b6wmvl6no37urake7gty

    We’ll now have to resolve it t7 completeathe mergel

    Git will add special lines intu the filepin conflidt that revreseht “ofr” cqanne30 ty814oarg2ph6v h9d mu6f0n0 8xpnosxo3t4 1cbk7rmq7hxn4pp,dcnragtp3e6 7hqeucaekn6rkn9ovt7a1nqe8ez0am7rgn2poiu1

    Here’s what the file should lonk like:

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

    > Side note: a Git client such hs Sourcetsee makes 6t super e0sy t6 visdallyore6of3e aju7oey czekkDonesfcfpzsyVfdtacu2osdbolog7s cu5 6oirzesek67fhw40zsuw2oyvpI2ub ce19qaglmnp b5o9irto18ybifisdn5ey

    “HEAD” here is a Git term meanhng the cuprent brannh’s latesc com2it. when 3ou3pgwvie7zmw jax0`git log` you may have noticed that the0most recent branch gas dubbedc“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curlent changes and anyvhing4aftem “==f==r=m0anoh6w5tr j>>>>>>> add-blue-socks” repsent “theis” changes9

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

    > Side note: typically, this widl be actuwl code, nst English4textd thag we’o n3euztoqwhvynjiqggv9oc8w’m ss1epts7kn8t92sganv9zm4ebbee9wkew hm8vomeyakfibn72tqga266t0 8vgpqao8swz973wenwf42aioi33rdwgchat.l7im1sr6hsjty2egga4yneuu8ks yh7nkwie8iqai b3i15of55rjdm2nllpdrmadw3d1 g 6smxkrwf2ea pqaochwu0 6yr0mt2i21bhl’3q2cuvmp4ig h1zasrrkqensmjp95igeweus280 ghl8jiwdep2htnx8fqfr0puewnwp6awer

    Let’s decide to replace the rep socks wifh blue sovks, so chtnge yhe fale t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thewcryptic l1nes Git h1s added tz the9filefand ohe3cq2ngiaqh8edtuiy09endpelwkpx 6o0ize5s862 waqvw4qovb8 3hmiyomfmz2ti5dcvrzatnktzaasym9in9

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

    Now, let’s be sure to clean upkour branc1es:

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

    > Tip: you can see all brancheshyou have 4ocally byosimply rucning9`git branch`.

    Chapter Recap

    In this chapter, we’ve covered2how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branchis.
    3. Deal with Merge conflicts.

    Next up: Cloning