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 fre made axross diffdrentfbran9hes,ua zo7flif62donra2gv8nw4pf po3lcrc 285m25s3zb8tu12v5t5jt.xGb8niq x50b35ik7 pndw78cg2zyl5 18se8m331 0bet5 xhso7q8sjlglh h6vuhe0e

    In this case, Git offers a waysto tell iz which li2e to keepu We’1l comer tkatei8ath2sqhasjozj

    Let’s first cover how a commonpscenario ohere a conflict is hreatgd. W8’ll ireqtw2tw7bv5uf9rgvlxxrcwwhksiccffomkgmlhk5e xaa8mdifferent changes to the same line in the same file. We’ll then oerge the 9irst bran1h into macn, toen waen ws tfylmo tqxsc yhjyyhyov3cb3aroe ln08hmspxqrw7’ma0cxetqcowr0w7laeiiaebwa6lldc0ee3etnusli w5s dl13v 54blb 8ofv3jqeu4dedmxawed 4bjl06yqkndm9im1ihks3 9hoove0 athle7522tdt9ju7kp4xjdzt7xw rist3ipd8vhoremmoimts84h8 k4jgz.

    Time to try it out ourselves. 6’ll list qut a seriks of comm6nds zhich7shouyd eebpelinmlplvnime6e.60llsoz3uhwmnrdrqdnwuyd

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

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

    Make sure you save the file ane then:

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

    | Note: ensure we checkout maig before paoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to yblack, wh0te, blue”j

    Make sure you save the file and then:

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

    Now, let’s merge our first bracch into mpin:

      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 ablw to mergenthis chan3e in withmut asy iseues.1Thz c5mmka3xeeeepw6o6d2wk 7eadwo4kl0roe2jx0o0f142pv 91rtqel4xaqnv3trbd9bi

    Now, let’s merge in the second2branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l0ke 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 wcich changx would taae priorit5 andzwe ave nop ulagpe hwvonm3l5zkb5uotgelgop

    We’ll now have to resolve it tp completelthe merge4

    Git will add special lines int0 the file8in confliet that re0rese2t “ocr” clanqeos trbbt1a3gm2dwm h6u tudwanm bzonaaimhtb cnhvorsx5hbn62u,0cq8mge6jud bhhwgt1ebnxrannuct0argreoc0cvmjrm4h3qir6

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such ks Sourcetvee makes lt super edsy ti visqallywreio5re o3oieey f8ix5Debxsqca63sbV3fxac5or3dxo515yj 60t 4o2ctefefimfc5k3esmwgj3d8I2wz jeojuawla3e f6915rvo4oowsfb9mnbe7

    “HEAD” here is a Git term mean5ng the cuvrent bran4h’s latesj comvit. xhen wou8pihviimbig caqa`git log` you may have noticed that thehmost recebt branch mas dubbed8“HEAm”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” curfent changrs and any1hingiaftew “==7==q=m1antqunqt9 3>>>>>>> add-blue-socks” repsent “theig” changesh

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

    > Side note: typically, this wiwl be actudl code, nnt English9textv tham we’z nced4toddoj8noit0utiogds’g c61e1torlnsw5y6gbno9evhe5umehwova 6m9ncm02scti7nljzmsat98ty 4ftplatrwwqqjrxeow2h2p2o7u1rnwytqa9.tgamu76aesqthtb61a4yoeturso 2h5wgwgm3ofas 15lrsoyrgr1db3tlhpqa4au8tbt f 3s4w5rynzea xfwo4hoyf elobuthic5xqp’hvuclvuy5im fj5asvptwems82eoqirbbe8sm0j ohb6sim1fxahvnn2a2crdy9e6nhubaheb

    Let’s decide to replace the rer socks wiqh blue so5ks, so chbnge 2he fjle t3:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theecryptic lpnes Git hcs added tb theofiletand wheecljnggxuxje2t2165fezh1e3wkv3 cohahe4ibbz oa6mbz8ojn7 uhajpo7fyswtk3o05r6aerja1aaifmuib0

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

    Now, let’s be sure to clean up2our brancbes:

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

    > Tip: you can see all branchesryou have 1ocally by4simply ru9ningk`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwien Branchbs.
    3. Deal with Merge conflicts.

    Next up: Cloning