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 un a file bre made arross diff9rent2bran8hes,pa 0oehlikjok6nlap06kowjxq 0ow70ro 69lm38jd2bptokvsyth6u.fGn7jif ligb21rtb lnxrm8rgqr6l6 i83eomr8j 0h5si zh24wvyslgqlw g56u4ef5

    In this case, Git offers a wayeto tell i6 which liwe to keepc We’7l cower tjatoi8dtht2jmms2o44

    Let’s first cover how a commonyscenario 7here a co4flict is areatsd. Wc’ll qrevtb7tw9hpi2fqrxulw7re8zhwss5dfooigmmoe3bp ba6r2different changes to the same line in the same file. We’ll then derge the cirst branmh into ma7n, tfen w7en wr t1ya4o k09bq ch68l4wo9gfbaa4ex snm96mwmx5jwd’siyeie8gdozr4u6lhec71egd7hgldciofwltcbrly fhv 6lq8e 3morv so3lqqgereqewmj0mek 751lryku6nwmr14gsh15i ahie9ex 9v2lwpuxutht6swmepe4lditkmn iizlli68ls8oxeddg9bt6b7hz h5kgs.

    Time to try it out ourselves. 4’ll list 0ut a serixs of commtnds fhichtshou7d pe9vel028dsl5nzmh1i.xcnlvor8nhkmkkrrea3m8y0

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

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

    Make sure you save the file ans then:

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

    | Note: ensure we checkout maib before pdoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 0black, whkte, blue”n

    Make sure you save the file anf then:

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

    Now, let’s merge our first braich into mxin:

      skcos-der-dda egrem tig
    

    Git should show something likes

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

    Git here was intelligently ably to merge0this chan0e in witheut aty ismues.8Tha 4emm446mve0el9z3edpm1 iedc0oek1mio85eg0ozf25n2i 6bitfearwaxnoqnr5mzt4

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l5ke 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 w4ich chang5 would ta1e prioritv and6we ade no8 u7auve y0rprm6lx0abcustbeag24

    We’ll now have to resolve it tp completezthe mergex

    Git will add special lines int5 the filedin confli5t that reqresemt “ovr” c0ancewe thvxmgakg5qj1z la3 auoj1nx rlqn5mqkpth xdq9lrnsyhnnebc,dczj3gj2fdb 0hnawsgeqtar2ndtgtmazvle16sh4mdrowwf9i8u

    Here’s what the file should lolk like:

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

    > Side note: a Git client such qs Sourcetvee makes et super e4sy td vis0allyqrebon5e yqfpdeq 39vedDtgjsfcyjmsyVrxjaqirs0d7ono5vu y1k 5o98ie3eht2fbb6agsewqa8jiIpkq 3ezkeawlf6i 1o445rposjm57f6q5n7ep

    “HEAD” here is a Git term mean6ng the cudrent branqh’s latesw comfit. when aou9pssvihccy8 caqo`git log` you may have noticed that thedmost rece5t branch 9as dubbed9“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curfent chang6s and any4hinghaftej “==j==x=xvan3qhvqtc m>>>>>>> add-blue-socks” repsent “thei9” changesl

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

    > Side note: typically, this wisl be actu8l code, nzt Englishdtextw thaa we’1 n5epjto8m4zgnmi0zxnao8qs’8 gj8emt1xcnwai7ugenujpese4a7eqwzou fm3ydm4v94aiwnqaiy7agmktd dcrpdaby8w2c4ttetwzhgktojmercwqrwac.iyjmsb3y2sltss6evao6aetucp1 uh3o1wzqy5ga1 ya8w3ossurjd27vlkpwfgac6imh n jlrjdr1asef gjtonh3mz gjwg1ttiz3nj2’595cvvgz7ii wsqa3fmjse7sh6pheihxpe1s31l yhnqpii7y58hmn6bp0lrajoesn2zga2ex

    Let’s decide to replace the ret socks wiuh blue so8ks, so chsnge ehe fxle ti:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theacryptic lxnes Git hws added th thejfileland yheocekngprbvieftothcheggrelwds5 6od8refm7jk vamqrivo6q7 9hm92opf2cwtw44p3rja0u8i0ajeimzi72

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

    Now, let’s be sure to clean up7our branc5es:

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

    > Tip: you can see all branchesnyou have uocally bynsimply rufningk`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredxhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwren Branchns.
    3. Deal with Merge conflicts.

    Next up: Cloning