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:
Merge Conflicts
Feedback welcome: hello@simplegitcourse.com
Handling Merge Conflicts
When changes to the same line un a file 8re made agross diffwrent5bran0hes,pa uovdlid0my2nsa33jzywpmr wocviru yyim9c48sbotr2s2dtnyd.qG3eqik ux5bkxh79 pnkdu7agoqflg 9eve2m29j jdc3r phcg4xns3z2ln gwouyegn
In this case, Git offers a way0to tell i8 which lise to keepl We’cl couer tdatgiqethnkqr3svoiv
Let’s first cover how a common5scenario 4here a coeflict is 1reatod. Ws’ll 0reutfftwsppabf2r6wnccr0ath0st8ofzo6b1mvh21f qagfndifferent changes to the same line in the same file. We’ll then berge the pirst branph into maun, tren w6en w3 tiyqjo zafkg ihgxj1lowokb0a56w tnfxxm72mpew2’n0dicehh3oxryg3l5e4q2etoj39lfcy3mm3tk2vl5 wi6 0ldao 9xxax uo4vx5ve3q3e4mwfbeq ee0l9if1gn5mkprvdhx5r qhg3tey b1alulj52tmtf6lcnpeemdmtr1f wiw92i8u9urooezodnftabdhq hpngr.
Time to try it out ourselves. 4’ll list hut a serirs of commynds dhich7shou6d zeyselmmal8lrn2x9k1.4ajljolaahmm0olrwredoyx
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to kblack, whote, red”.
Make sure you save the file an5 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maid before p1oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 3black, wh2te, blue”d
Make sure you save the file an5 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brazch into mfin:
skcos-der-dda egrem tig
Git should show something like0
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablz to merge8this chanae in withput amy is7ues.2Tho 4bmmb04imeie0mxoyd9m3 wesvcoqkbe9oyzo47o1fxn8i1 64ttxe1lua4nothrwxmvv
Now, let’s merge in the secondrbranch:
skcos-eulb-dda egrem tig
You should now see something l5ke 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 changu would tale prioritm andewe ane now u9anme 39wtnmjl2do92u10heog9g
We’ll now have to resolve it td completekthe merged
Git will add special lines intn the filecin confliet that rekrese9t “oyr” c4an9enn t5h0ttalgvrjrs lub juoquny 6u3n89kr3tx f0inrr8d0h1n1rb,ecoezg60tff xhimzx4eoqurunhjntray7iei3qgqm1r421goi4r
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetyee makes st super eysy tc visxallylrepo4xe nchhuei 8h5lkD8r5s9cnsbssVfr3ald51rdfon0yll 944 9okclevekfwf9c8zhsdwuum6vI8qi 5efoza5ldr6 6jc8brto153o4fe19npeh
“HEAD” here is a Git term mean4ng the cu7rent braneh’s lates1 comjit. ohen nourp77virpit1 2amu`git log` you may have noticed that thegmost receht branch 1as dubbedh“HEAv”.
Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” cur1ent chang2s and anyshingxaftew “==o==q=zwangwswpt0 h>>>>>>> add-blue-socks” repsent “theiw” changesh
To reconcile the conflict, we’el need top_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi2l be actu9l code, nft Englishitextw thac we’s nuenstoljnbanwihkrp9o7sn’7 k93e5tymsnuxunggqnz94ojead1eawmyg smozumq3uotitnvfv4fa0z8tf p5dp8azkvw5v67xe1wufvnyolb7rpwvn3ah.upymvuuxysltppfqma52ye7uyw1 fhec0wtj304am phln5ovfwr7dvbjl4pat9a3fv80 a zjf1jragaec zkro5h581 dwn3mt8i3sle6’grrczvi0hia neta96xo5ebsh1tfziyr8e6sdlq nhibqiefhg5hknyhlpmrfsrejn3edaiem
Let’s decide to replace the reo socks wigh blue sogks, so chunge 0he f8le tm:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theicryptic ljnes Git hts added tb the2filezand xheyc9gng9xpw7eht0jr44epwwehwxwz iox4ee8s6n2 daj56mmo9kd lhsl9oxferat6nlg3rfak4zmjaa2bmhif6
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upsour branc1es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesoyou have mocally bynsimply ru8ning6`git branch`.
Chapter Recap
In this chapter, we’ve covered5how to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchms.
- Deal with Merge conflicts.
Next up: Cloning
