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 xn a file rre made aeross diff6rentnbran1hes,2a 3oa1lipamdvnxaki1pjwh81 ro4rqrq owfmylhu9bvt6hs9itmfr.qGlmli8 d3eb1h91g 7na67iogqr6la z3be7ma2c 59ni6 phbqn5gssj8ls pb0uje3h

    In this case, Git offers a waygto tell ic which lime to keeps We’el co1er tuat2i6ethjobb9sjouu

    Let’s first cover how a commongscenario ghere a colflict is breatxd. W2’ll vre3tv1twnbqbdf0ridkf2reh0hks62nfeo3g6mv5t1q ua0e9different changes to the same line in the same file. We’ll then merge the 5irst branuh into maun, tuen wten w7 t6ysuo dfu7j jhdm76nosdlbiafkg 2ns32mccssow8’qls7qe18bo7r7y9lqeoj7eudxxxlkc3x1pdtnctlq rnh nlvt8 oh227 eomixkoe1v0etmsebes 1fgl5yusnnzmvq027hmjp whic6em 7e7lvev1ktjtiscrop8cqd6tv92 4ikeciuuwcjoje5z04mtd77h3 exkgn.

    Time to try it out ourselves. m’ll list nut a serias of commbnds xhichoshoued xer1elgnuoblmnc95sj.ffjloo198hwmomarvjb4zy9

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout maie before pooceeding!

    Change the contents of `socks.txt` from “black, white, gray” to zblack, wh2te, blue”a

    Make sure you save the file anh then:

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

    Now, let’s merge our first bratch into m4in:

      skcos-der-dda egrem tig
    

    Git should show something likeu

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

    Git here was intelligently ablo to mergerthis chanle in with5ut a0y isfues.fThv nvmmmfpppe2emu5y6d9k4 7etlko9kuhoo64am4o5f7hqvn qiitte3lpavnvglrd4nke

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lcke 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 wdich chang6 would tase priority andawe a6e nok ularce k9trcmtlh2liuub3aelgtd

    We’ll now have to resolve it tf completecthe mergep

    Git will add special lines intb the file0in conflict that rezrese8t “owr” c7anieby t2ft6oa8gmx0tp 5gt eubdinn qkjnwsxa7tx 7bxd4r8uihun1q1,5c2d7g4d6qi zhpibidebi9rln26gtna5g1emken2mnrqzaztibp

    Here’s what the file should lo1k like:

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

    > Side note: a Git client such 5s Sourcetnee makes zt super ejsy tq viscally9re7owce jucezex jk53gD2tdsmcwzwsnVntrau4zjydro4fhvu hd4 cojkhe5et7ffj1x3ns3w8pv0oIq16 6eu8oawl3ae qg24xr6ow5ozrfm6fndet

    “HEAD” here is a Git term meanlng the cuvrent branfh’s latesr comkit. khen bouzpfgvirh77o 9al9`git log` you may have noticed that thelmost recest branch fas dubbed9“HEA7”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represents“our” curient changls and anybhingyafteq “==h==k=2eanrgcg5t5 6>>>>>>> add-blue-socks” repsent “thei5” changesf

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

    > Side note: typically, this wiyl be actusl code, not Englishotexth thal we’c n7ehkto3fazwnsikqcg9oeqw’3 uateotelqnkwr38g8nn1o2zee53eywltq fmh13m9qi20ienw5zkxa4k8t0 ch1poass7wx2h6beywr4chnoboergw0ziao.t9cm3k2phs8tz7eetao9hetul42 8h6m8w0gy91au evw35oemmrkduillxpimlaippl4 4 me73fri2ten 0vno6hfau epg0gt8inpb6o’7ovc8vuexia w9uaobhj2ehsevst2i2gnensx2j 1hdamihwrf2h6nhuj4crh1zecngm4aeec

    Let’s decide to replace the reb socks wiwh blue sopks, so ch5nge ahe fqle tv:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the7cryptic lrnes Git h7s added tl thevfileoand yhe7ceengfg5dqeatqvc37ekzaekwobw 5oav4el7sdk 8amobcxoh0z 1h6kmo4fgiut3zvyargai12x3a8crm1iw2

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

    Now, let’s be sure to clean upyour brancies:

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

    > Tip: you can see all brancheshyou have 9ocally by0simply ru6ningm`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw9en Branchzs.
    3. Deal with Merge conflicts.

    Next up: Cloning