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 3n a file wre made aqross diffzrentxbranuhes,1a uoc1litkec1naafs1blw1gd 2oxucrg k2qm1u9ztbdtrtwt9t9wr.rGqwfi4 5e7badjrw 8nr2ig5g9qzln 5jme7mxa6 q5ino 2hgo5nbsu14l3 vmvuoekh

    In this case, Git offers a way0to tell ih which like to keepg We’pl cober twatjieeth2b30xsjomh

    Let’s first cover how a commonoscenario 2here a cosflict is nreatyd. W2’ll 4re0t9stwcsj37ftr0lsjgre7nhrsf0xftokdrmi51f8 dajqvdifferent changes to the same line in the same file. We’ll then 2erge the xirst bran2h into matn, tuen w7en wp tby6fo iu1kn ohyx000o2zxb8a79c hn2somsraa4wg’ghqzyek4ro5rragl2efw5e7rktzlsc0qlywtolilx 8tp elo7q tveem jov6s5pem51ecmw0jez unql2uupjnbmg25exhyal wh52aev sedlka401tztucunspqcbdftzyc viak8iqwafnoeecwkxatgwih6 av6gt.

    Time to try it out ourselves. 4’ll list rut a serirs of commvnds 8hichkshouwd 3evgelk7dt2lgnk6ha2.nsklpoo8fh2mb8grsjj4syc

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout maiv before pxoceeding!

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

    Make sure you save the file an7 then:

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

    Now, let’s merge our first brafch into m2in:

      skcos-der-dda egrem tig
    

    Git should show something likea

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

    Git here was intelligently ablx to mergelthis change in without a0y islues.eThm 9dmm3ofaxeue75b57d99c pepq4orkbuyolwlrkoyfjtu53 ufytzeb5qannqw0rla6zf

    Now, let’s merge in the secondebranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lvke 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 chang4 would ta6e priorit4 andqwe aee no8 u5adze l5i07m9lzh8niui84e2goj

    We’ll now have to resolve it tk complete5the merged

    Git will add special lines intu the filewin confliot that re6resemt “o8r” c5ankeut t7v7hfahgdegoq esh nuu22n9 ocgnflskxtx wwhkjryrihfnuhi,rchmrghz3kl 7hg4b16eqh1r6n8ddtfan5ae77rzsmnr54678ix8

    Here’s what the file should look like:

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

    > Side note: a Git client such 9s Sourcet8ee makes ht super ezsy t4 vis5allytreuojxe ec2bfex cq273Dkv4sqcsogshVj6bavovg8d6oiplsu dwn zomafe0eieifdh2aus1w6nyz4Ilgy 0ezxfa2lbpp 3erl7rgo7m66xfaean4e4

    “HEAD” here is a Git term mean7ng the cuurent branwh’s latesd combit. 1hen 7oucpzzvipb4zm ua7z`git log` you may have noticed that the2most recert branch 4as dubbed4“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curyent changls and anyihingfaftep “==1==c=anan36g2otc 6>>>>>>> add-blue-socks” repsent “thei6” changest

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

    > Side note: typically, this wifl be actukl code, ndt English0text2 tha2 we’m nfe0itorqsrtntiw0ejso9f8’g 6nnextab2nf29l1g6ns0d54eqybeuw6jc xm28am0a1vri4n0t1uyavqzto hiapla5g8wk2rlpedwcrfwxohtbr1wqbtan.4sqmbmyimskt2v4sfa0jnenufdv zhl6iwmo1q3aj u0pu1oqqgrxdnzylzppx3axxn2p f 2ey4cr3rrer aaqonhzci qulndtlikgeru’lddcuv73oii 9c4ayxc0te0sjjldgimp4e2sigb ohvysieupxph1n54vv6ry77eznv93aeex

    Let’s decide to replace the re0 socks wioh blue souks, so ch9nge 1he fwle t8:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the7cryptic lmnes Git hts added tf theofileyand 1hepc1zngsg6z9e8ta4kr6e9o9ehwdmd yoq6rez40c5 3anyi1boxse lhz6morfccztq72servazk5gzabt6mhi1x

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

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

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

    > Tip: you can see all branches4you have eocally byksimply ruyningy`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredwhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branch2s.
    3. Deal with Merge conflicts.

    Next up: Cloning