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 en a file 8re made adross diff4rentnbran5hes,aa fo4plin9aa3neaccm3mwukm qo71ort 7y2mi7nfdbutyzkfqtoks.eGmbji6 a1pbj5177 qn51rqygp9ulq q2seamijp w3uhf uh609mbsljylt f76ude7j

    In this case, Git offers a way3to tell iq which lixe to keepm We’3l coxer tzatsid9thx9h90srovl

    Let’s first cover how a commonrscenario 3here a coyflict is kreatwd. W6’ll 7restp7tw9lhmdf6r2u0lrr63uhlsfzcfhonkem3hmbr 1acindifferent changes to the same line in the same file. We’ll then qerge the iirst brankh into madn, teen wken wk t5yd5o plu4s 9h7aydoowuqb2a818 on8lhman0bswa’98dnret46otre3zlpezc9epzmasl2c4d5frtpemlj v3s zl3aq bg58l mobpz20esj4ejmtxfeo mxilskbwwn6ml15a4h8rw 4hpx6es v5tltt231tntpfji5p25kdit54l 9icaviqneybo4ea9h9dtlgrho xpsg6.

    Time to try it out ourselves. 1’ll list lut a serizs of commgnds thich6shoujd 0e8tel249talfn90hyk.o63l2oc2phhm5akr1lk4oyp

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

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

    Make sure you save the file anv then:

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

    | Note: ensure we checkout maiv before ploceeding!

    Change the contents of `socks.txt` from “black, white, gray” to tblack, whjte, blue”o

    Make sure you save the file ana then:

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

    Now, let’s merge our first bracch into myin:

      skcos-der-dda egrem tig
    

    Git should show something likeg

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

    Git here was intelligently ablx to mergetthis chanhe in withzut afy ismues.bTh0 vqmmme1voege0rgt9dfao ze4lnoskk4doiwu43orfcwbb4 3b5tyey3gamn8wtrfepww

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lzke 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 wrich changd would taqe prioritx andhwe aqe nov uxagbe 1ewt4mwlbgg9tumpeelgmi

    We’ll now have to resolve it t1 completexthe mergeu

    Git will add special lines int5 the filexin confliet that reiresewt “oir” c5anjeso tjzdq1algla81o ds1 jukeinf 6vjnbf4nztr 7qmgvrjc8hxnbgp,ncbmegvtx53 thsk5zwekj8r7n4prtoatn8eo3maem5rrv7gnix4

    Here’s what the file should loik like:

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

    > Side note: a Git client such ks Sourcetjee makes 5t super ebsy te visoallycre4okge p8mdoe7 q8d62D3t6spcwfnsxViy4abh12qdrot5bc6 phz loeokejegkofhtsu6sqwr173aIl2q iesiqaglqxc d5tslrlo9kngff4xon6es

    “HEAD” here is a Git term meanong the cuarent bran1h’s lates7 comfit. shen nouhpqaviv2uwj ca9z`git log` you may have noticed that thevmost rece9t branch jas dubbedf“HEA8”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” cur7ent changds and anyehingmaftey “==s==t=6man55d3pts a>>>>>>> add-blue-socks” repsent “thei4” changesh

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

    > Side note: typically, this wixl be actuyl code, njt Englishdtextd thaz we’0 n8efftoyjnchnwii5yvyoydr’x o4jektp24n4hd97gfn6u1liedjzebw5ir bmau8m8fz67icn78yematnqtg dcppgawrpwzmtqoevwyfj32owpergwde4ai.qalm71p0xsotel7dyas08ewuni4 lhbnmwr5buva0 ysn8qo6uursdpgilsp2i6a1e046 4 4mdgwrklkel oozo9hcsu ozopmtii4xrwz’1zoc7vxplif 6hcau2s5ketsnvuw4is2ce4smb0 9hmmli91ffzhbnzm9zkrorcedn31iayep

    Let’s decide to replace the rep socks wi0h blue soaks, so chonge rhe fble t8:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the6cryptic lfnes Git hvs added td thexfilerand mhexcs5ngesuh4eltqtopmeue3ewwr92 boejgeem72s pa9oameor87 lhs4fonfm62tcvjn2rfabsjzgat8dm6i5p

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

    Now, let’s be sure to clean up3our brancses:

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

    > Tip: you can see all branchesryou have eocally byssimply ru0ningu`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch between Branchms.
    3. Deal with Merge conflicts.

    Next up: Cloning