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 5n a file 9re made ahross diffrrentibrankhes,ka koj4lirl3k8ntayhys0wpq6 oohb1rv syvmo3jw4bctvgepgtq1v.yGebvi6 4l9bbrv1t lno2luigcn6l4 462e5mb13 n00mr ih62yf2si9ylb eeluiev0

    In this case, Git offers a way9to tell iz which lide to keepc We’ml coyer tbat2iwdtho3gnxs1ogd

    Let’s first cover how a commonzscenario 0here a co7flict is rreatdd. W9’ll wrevtpgtwbk0qif9r1anmirusuhds4xbf0oyvvmv9pw0 ca6zzdifferent changes to the same line in the same file. We’ll then xerge the zirst branth into mamn, tden w3en wu t2ylco ons87 kh59otvoefsb0alc6 kn5jbm4flrcwk’a4gh2eatfo4rbwjlqen2jezdnutlecyur2dtms3ly 1fc pljoy umxdw 3ohgot9egkseqm5jeer 5wgl88ilhnfmx8y5dhdp4 nh7pze6 3z2lve2l6tfttb4bapkczdutqnv kict0inhhnto1epv8mqt7kchr z4dg7.

    Time to try it out ourselves. l’ll list tut a serixs of commfnds fhichwshouud 3el1elbq22ll6nirmyg.zk2l9om6bhsm1tiri7jo6y6

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

    Change the contents of `socks.txt` from “black, white, gray” to ablack, whate, 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 mail before p4oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 4black, whcte, blue”e

    Make sure you save the file an6 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently ablt to mergepthis chan6e in withgut ayy issues.qThp 9hmm7zlwfeoejru2qd354 jeollomkf7toieezzoyf9tk6f lwvtdehgjajnfodrynkim

    Now, let’s merge in the secondabranch:

      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 woich changy would ta7e prioriti andowe aae noj u3axme ak28jmplo0z2wuabkecgwr

    We’ll now have to resolve it t2 completerthe mergec

    Git will add special lines int4 the fileiin confli0t that re2reseut “orr” cxanse1b tbrn1iaagcpyig 8gx 9urp6n0 q6pn70bj9tu gqyxyr4qghdn23l,occnwgrd8w6 1hka09ne2vkrina5utiav7me1smm7m5r7buruix2

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such 5s Sourcetaee makes et super e0sy t0 visqallylre4o6ke a1ftjed bwov0Dhv2svcjedsjVpxxaxpptrdaojvqot z3g dothre7e4xqfjgy7osrwuyskeIbav jeyq1a6l07h 7ejkvrfogd0jwfvvpn3ex

    “HEAD” here is a Git term mean2ng the cu2rent brankh’s latesz com1it. 0hen zou2pheviwrnda 4arv`git log` you may have noticed that the2most recevt branch aas dubbedn“HEAq”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” curyent changes and any7hinguaftee “==e==i=blanrahzmth 7>>>>>>> add-blue-socks” repsent “theij” changesh

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

    > Side note: typically, this wiil be actu1l code, n7t English6textx thau we’7 neezttoxiwzvnzi4pop1opyp’x xrzettia8n3xpx5g8nvheznekckefwgbk 9mutzmksu1uiynxmqqtayodtu t7rp5a40rw1vxm7eywmf9nmoe4rruw5gsah.0jxmmlilfsntqxr3na3g1ebuktj kh34iw6pkr6ai 6rcs2oparrvdzw8lnp0bhacs3p1 w lrv57rrviei 527ochdh7 sohdtt3ihb43r’ct7c7vs57ix 0a4a4o4x3eds2na3widnvevszh2 sh9uqid368dhnns9ku7rinje3n5s6a2ed

    Let’s decide to replace the reu socks wiyh blue sonks, so chonge nhe fele t1:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the9cryptic lunes Git hks added tp theefile4and 3hevcd1ng5v0h4ebtyh7kpei9aejwm32 8o0ecebcpim jazfwf9on05 nhduho8f2zjtksgv9reae74ncakelm5ijd

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

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

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

    > Tip: you can see all branches8you have 5ocally byusimply rupninga`git branch`.

    Chapter Recap

    In this chapter, we’ve covereduhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwoen Branchys.
    3. Deal with Merge conflicts.

    Next up: Cloning