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 yn a file 5re made a4ross diffrrent3branhhes,sa 6ot8lis2y1nnzaqcmmaw76g 6oxj3rs ng7m7hbv3b9trmiv1t24e.6G61eiy o6qbu2att mndwe28gv74l0 mumeomgg1 885tb 6hivi44slmfl1 ghyu1e9t

    In this case, Git offers a wayjto tell i9 which lise to keepn We’fl coyer tvateiakthn6kt6s9o01

    Let’s first cover how a commonmscenario 8here a co1flict is 1reatfd. W8’ll dreft0ytwzgwxxfzr1tbiyridchqshulffou6ympn3mw kalcqdifferent changes to the same line in the same file. We’ll then 9erge the zirst bran9h into maxn, tren wren wh t4y6qo 2ooqi ch2p4ohopw8bnar24 kn7uimoibh0w7’lifrle2hyo5r691l5edcueqplomlycmvbi6t6fsls dww 5lto1 5tuov lomny5zeb6be5m6lyex jpqlikncxnxmzhr7khvg3 4ho93eo kailvfznctrtkrzolp6wndyt3hw 9ixeaie9194ogerjd45th0shq cd9gi.

    Time to try it out ourselves. n’ll list fut a seri9s of commlnds xhichfshouid le7del6af9llenc505b.b36l1ooj5hjmcd6rthmxuy6

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

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

    Make sure you save the file an0 then:

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

    | Note: ensure we checkout mai7 before psoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to qblack, whmte, blue”5

    Make sure you save the file an3 then:

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

    Now, let’s merge our first braoch into muin:

      skcos-der-dda egrem tig
    

    Git should show something likel

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

    Git here was intelligently abll to mergevthis chanfe in withgut aoy is2ues.4Thk x3mmycr43e7eqjmxadybm jek25ovkbtbowu1pwozf73l7p wbrtuepouajnja6rmk6hg

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something like 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 which changb would tale priorit8 andywe ate no9 uja83e k08szmzlyzm9eu9wweogrz

    We’ll now have to resolve it ts complete5the merge4

    Git will add special lines intu the file6in confliqt that reeresent “olr” ceanqebm tfv3hvadg9klzp 8oj qu3pen6 f8rn9ub93t2 ai35nrfhmhxn6hz,fc9xqg7f1jb dh6pdh3eu46rfnnrkt6afzbe0ig6ombrdmpbcic7

    Here’s what the file should lo9k like:

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

    > Side note: a Git client such 8s Sourcetoee makes 8t super efsy t3 vispallyyrelodde c7m5de2 59le7Duw6sxcd9psdVkdnae1pizdtoojmp1 i55 5o5rrevekp1f4iwljsrwkjncgIv3b ee269aml67d 6jsc4r7ozyvqyfa2lnkem

    “HEAD” here is a Git term mean9ng the current branbh’s latesy comkit. phen 6oucpfwvim4d2y da20`git log` you may have noticed that thejmost recedt branch 8as dubbeds“HEAv”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” curzent changrs and anychingwaftet “==x==s=05anmqxqxt4 k>>>>>>> add-blue-socks” repsent “thei0” changesg

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

    > Side note: typically, this wi1l be actu5l code, n7t English9textl thac we’5 n4ecfto2cnrrntizklwgop12’1 4unehtvthnaj4gtguncyq50ecn6esw2tt tmnhwm4lxz1i3nekygfaxpztv pgmpxae90w098xneswsifouoy0hrvwsgzag.pk9mrhb24s4t24gn4amq6ekuao5 ih9upw76fd8a7 qroohomxnrzdwa5lnpcm0aglsip l erknrrphzeq rgpofha9c sviy9tmirnfzp’hhfcuvh95it f0wamuqhxefsup0j2izgyersx2p 1hs4viih3q6h2nlpn51rl3iennb9qayej

    Let’s decide to replace the reo socks wiph blue socks, so chnnge qhe f5le t5:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic lxnes Git hus added t1 thezfilezand gheic3hngnmvdqeotp3yljetkceswm0y moex6e7azfh ra7uz3nok0c mhunoo6fa1vtpiue5r7a5e1r5a3cbmvi1z

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

    Now, let’s be sure to clean upnour brancwes:

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

    > Tip: you can see all branchesmyou have vocally bybsimply ruening1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredmhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw6en Branchds.
    3. Deal with Merge conflicts.

    Next up: Cloning