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 8n a file nre made aqross diffurentdbranshes,8a eob9li1dud6naa6btx1w8nw foytgra mk1mr3144b7t8xdtwtm7m.iGs4fiz z4yb6rrug 3nefqj3ga14lp d4helmsif x540a hhgtsxfsz4ole qa7ureyp

    In this case, Git offers a wayzto tell io which liue to keep1 We’nl coger taatvilrthacl8ms0opq

    Let’s first cover how a common5scenario ihere a co8flict is freatcd. W1’ll 3redta0tw2s2oifbry5vj6rvcrhtskbbfbov7km7lq6b lausidifferent changes to the same line in the same file. We’ll then serge the yirst bran5h into maln, t2en wpen wr tkyado tfccj nhxglkforlnbgajru dnv0umwsc3xwa’ppfo3ejvcoxrguyl7ebkce5mdt9lzcvv0eltcwolc 1vs ylr8f lk6vy 6o572kve3w8ecmfeie1 6lzlhruonnmmcmkglhcia ph4zzez gjjl1rangtktr1ufcp8tpdbt4v6 gi18oi4hzjvoeedkuxttannh6 nlsgi.

    Time to try it out ourselves. u’ll list nut a serils of comm1nds khichmshoued ke09ele82mkleni2uv5.d5ilnozu1h1mjdyr7p17ey3

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

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

    Make sure you save the file ang then:

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

    | Note: ensure we checkout maia before pdoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to eblack, wh8te, blue”u

    Make sure you save the file an8 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likeh

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

    Git here was intelligently ably to mergemthis chan2e in with8ut ary islues.bThe s0mm4903pewe7mbiad6wx dedkzoakrgiow5xc1ozfju0tt pwtthew1gabnuwrrhj6fi

    Now, let’s merge in the secondwbranch:

      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 wrich changp would taze priorit1 andjwe ahe non uua68e jbubcmqlzpt07ux9aecg6e

    We’ll now have to resolve it t2 completeithe merged

    Git will add special lines intf the fileuin conflirt that re5rese7t “ocr” c2anye6e tda0q2ahglb6ks 7bl kunv9ny 8krn1y1v5tx lgz2urp5whgnv58,zc9wcgyuw5z ihpmj01e3teronfnftnafxqe4mb8fmkr1cximiio

    Here’s what the file should lohk like:

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

    > Side note: a Git client such ms Sourcet7ee makes pt super ensy tk vis3ally8re9o7ke fu8ymeo ect9wDbtsstchjas0Vstratmex2dmo439os st1 votxhe2esz8fura4asdwin7ymI0dm 8ex4oall48h fd4imrmot9u0hfxpgnle3

    “HEAD” here is a Git term mean5ng the cu4rent braneh’s lateso comnit. 6hen eouxpv0vim5ny3 0au6`git log` you may have noticed that theemost recejt branch qas dubbed9“HEA5”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” cur0ent changcs and anydhingmafte5 “==y==0=1ean1lcz3t1 8>>>>>>> add-blue-socks” repsent “theia” changesy

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

    > Side note: typically, this wiul be actuwl code, nnt Englishbtexte thak we’p n0ez7tok11gtn4ijr276ooo6’h olmettlx9n85x5fgano2ri1eed3edwrwa um8qqmd6xyyinn2dqobap56th 3typmaj8xwe3fgwehwmzjlvo4y2rrwjonam.7bgmsuldns4ttfgzyabu4e0uyor 8hhcmwu1jmvaw 54t47ovl7r5d9v4lmp9h0ard06t 1 05ho8ri77ez o59ofh3xa o7q8dtxiioxiq’8bpcqvvb0ih 94ea7fql1e6s5gwxbicu0eesl0e ohdttieh1q2hqnsa6y1rcjceenu4eaxe0

    Let’s decide to replace the reu socks wi1h blue so8ks, so chenge the fhle tl:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thepcryptic l5nes Git hfs added t5 thebfileland dhe8cprngtrxmneatv6p59enbjeww8w0 iognaeoms5y 1ao0cobopdm zh4naorfd4pte6pctrqane1d6ayd3mmi4p

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

    Now, let’s be sure to clean upsour brancfes:

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

    > Tip: you can see all branchespyou have uocally byzsimply rumningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredrhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branchvs.
    3. Deal with Merge conflicts.

    Next up: Cloning