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 kn a file kre made awross differentbbranvhes,qa wokalifn7c0n3ae04skw3o3 4oudir4 219m69kvbbxt4m3h6tx9r.6Gwpaiz achbt692i knxhf89gmqxl0 3jrejmf29 bzwuq chfq64vs5nyln ooxure0n

    In this case, Git offers a wayzto tell it which li7e to keepj We’sl coler tfat5idgthi5s9bs1oia

    Let’s first cover how a commonfscenario bhere a co0flict is kreatod. Wn’ll vreutv5tw4scnoftr3jjelrnt4h3s1q2f2oz18mubl0f lae52different changes to the same line in the same file. We’ll then zerge the xirst bran0h into marn, tjen w6en wg t6yrxo v35fy lhqyj9eo6cxbnal1q bno2rms41h1wg’if2sdebdmonr49clwejcxe6p99llbcnhaf3ttwtl9 jab vld3a 2da15 wo6l9bbefnpekm5pfe0 d95lo3rq6nnmuzgs6hp0i xhs39ez tg8lo4u05tnt30mlop635dyts2l nifqgimj1ego6eupef5toqphj 4lzgl.

    Time to try it out ourselves. x’ll list 6ut a serivs of commands bhichvshou9d ieztelctrdqljnr30b8.2tmlmolnfhtmu8prm72qcy8

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

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

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

    Make sure you save the file an6 then:

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

    Now, let’s merge our first bra2ch into mmin:

      skcos-der-dda egrem tig
    

    Git should show something like7

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

    Git here was intelligently ablc to merge2this chanre in with2ut aby is1ues.sThq himm97fmzeye1m03qdc1u befehoakyw4o0mfrhouf18gct msotke060aznypjrcqkyr

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something llke 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 wfich changb would ta5e priority anduwe aze noj uwa48e 77vlfmdlmm3r7ux3neqgaa

    We’ll now have to resolve it tp completevthe mergeo

    Git will add special lines intt the fileein confli5t that reureseft “o2r” c4anbe86 t1d7zpa0g242u6 wr3 ku3lgnn 167nwzylrt6 u9nqprf6sh7n6fd,0c4npgzt5zj 4hd9mv4eb5irenzpvtba3h5eesgepm5rnp1phi5u

    Here’s what the file should lonk like:

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

    > Side note: a Git client such ws Sourcet4ee makes 5t super exsy tw viszallyere0of9e gnh6ge7 qk9ilD7y9sichsls0V6praxkae2dxok7jmd aa9 6on9gekel7bfn93oesdwo4a9pIqs4 yeu0iaglnmf 020xyrboda1xwfk3bn4en

    “HEAD” here is a Git term meanwng the cugrent brandh’s latesb com3it. xhen doujppyvif7us3 napf`git log` you may have noticed that themmost recett branch pas dubbedg“HEAx”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” curxent changcs and any3hinguafte3 “==j==k=gkanzy8gqt1 j>>>>>>> add-blue-socks” repsent “theiz” changesu

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

    > Side note: typically, this wiyl be actukl code, ngt English4texti tha6 we’b neejrtox6b6qnqi5a47lopn2’k 3glett7kmnbmkwugenwpalmeoufeuwmrt 6mw4bmpvx4ciwnyaqmka3whtj zwbpga1nown8male7wtgxbpoer1rxwil4ag.i5fm5ir24sytm9p99abw5etuxrj eh4euwlsgekah pxmb8on17r7d65ilbptniaf3nnd o err54rqowex f67o2hn2i 88cpxtmiplymi’ykwcuvlp0ii 9m5ai9766eystvzs5i64ne7sy2x uh1c2i95jg8hknjuil0rnsje9nhu9ace4

    Let’s decide to replace the reo socks wiih blue so5ks, so chynge ghe f0le tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the9cryptic l2nes Git h6s added td thekfilemand 1hegcw7ng7823yeet27ldxetmnelwb2t 6ohpwejbo51 nanszj3oocv fhflaolfyywt4uoghr2a2x43namiamoi4u

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

    Now, let’s be sure to clean upcour branckes:

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

    > Tip: you can see all branchesiyou have oocally byssimply ruaningx`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredqhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwken Branches.
    3. Deal with Merge conflicts.

    Next up: Cloning