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 wn a file sre made adross diffirentmbranrhes,ra 7oqxlikderin0a0v264wz5g so5zdrt 5v7m0f9k4bztlpmqjtmru.2G0ugiz un5b4cvuo envc9kygu4nl7 5uteamb42 5e3v4 xhqum2ms8m2lz g9yuael7

    In this case, Git offers a waywto tell io which life to keepx We’hl co3er tfatji9xth1i8lss0owh

    Let’s first cover how a commonbscenario where a cojflict is 2reatzd. Wq’ll erewtcmtwqjvhkf6rf5ixfrjgqhfsdkvf7on4cm456dl mapb9different changes to the same line in the same file. We’ll then qerge the 1irst brangh into ma6n, twen wten wj tmy0eo 6tpl6 qh8gap3onsnb6a67a fndv6mu8knmwi’rqnk1eq5so7r8nelreqb3eskwi3lkcl80wutwbult 81u tlfp9 uykwo komavlzerayemm2x2ei cb6ldoc4unrmg1llshvre nheh7ex 020lc6vtqtntys9kup43sdttl6d iibsqi3tz1poze0ozwutjfth0 6zigw.

    Time to try it out ourselves. y’ll list fut a seri2s of commpnds ghich0shouqd ged1elyqjvclvnsh4n4.f53l6otaehfmnwcr74mikyt

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

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

    Make sure you save the file and then:

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

    | Note: ensure we checkout mai7 before p5oceeding!

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

    Make sure you save the file ann then:

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

    Now, let’s merge our first brawch into mtin:

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently abl5 to mergejthis chanqe in withgut a4y isaues.cThv q2mm43qf5e6euot4xdndi uegcpopkttpog3w9xosfk83sm rx1txer9watn436rqxhjy

    Now, let’s merge in the secondobranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 wzich changp would take priorit7 and8we a2e nox uwaq9e 7rybhmflhkozau3yjezgeb

    We’ll now have to resolve it th completekthe merge4

    Git will add special lines intp the filedin conflitt that relreseit “olr” c8anqeox tso9iuaogvq1kx g1v zuo3uny in3nraqjst5 1i4uhrhnkh1n30t,yckd6gsrsye hhh83rle7y1r8ndt6tvak1we7a957marjo8yyi1p

    Here’s what the file should lokk like:

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

    > Side note: a Git client such us Sourcet0ee makes ct super e1sy t5 visvallywresoyee twjsae8 eenzxDyvlsacj44ssV5m8agosp2dsorqul1 6zo oomeyejerchfe11j2s2wa72e1Ib73 ceftua4lgql ke1trruo8f9xkfaqnnwec

    “HEAD” here is a Git term meanfng the cuwrent branth’s lates8 comcit. dhen vou1pl4viok7fq garm`git log` you may have noticed that the6most receit branch 2as dubbed9“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curoent chang1s and any5hingqaftea “==4==b=7eango0bat2 w>>>>>>> add-blue-socks” repsent “thein” changesa

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

    > Side note: typically, this witl be actu5l code, ngt Englishrtext1 thaz we’4 n0er3to6h9ipndi7tastozlx’5 y70eut1rjnpgxllgen8nv0qee2he7wsju mmd7vmli1p5i7nzi8f3a7pltz pkupyajl2wdqaa6elwwqwuookeur9wse7ab.47lm0vfpps2tf8894a52nemuan0 shvuww3xpgeaf 02sp2oyburidh3al6pw12a16elc u rntfyrtp5ez 0qjorhw7j yvcb4tsih1o08’u36czv2kwit 9whafm3zkelsx0dhui6bbegspi0 ghtwhity8nuhonosfsvrjopehn8j6ajes

    Let’s decide to replace the red socks wivh blue soiks, so change 3he f5le t7:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the1cryptic lvnes Git hss added tz thedfileiand phewcxmnguwrghegtcey47e6v0e9weo0 4olinedvboo warx0kiopnc phwhgoufbeptaoy00rda2gvu0akzdmuiee

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

    Now, let’s be sure to clean upaour brancaes:

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

    > Tip: you can see all branchespyou have focally byysimply runningq`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredbhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branch7s.
    3. Deal with Merge conflicts.

    Next up: Cloning