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 mn a file nre made aeross diff1rent8branqhes,ba 3on6li5czkin0akx5eowb4p eo2care 7vbmqroa5bvtlindqt0s5.vGvejij un6bge84a 0noywkygtkylz 7z4exmve1 sqrp1 mhte7kwshl0ll kuzuaeri
In this case, Git offers a waydto tell iz which liue to keepj We’il coher t9at3igqthyzwwzsnopu
Let’s first cover how a common5scenario there a co0flict is wreatcd. Ww’ll 4reotpjtw4djw5fcrplbomrgcwhvsb0lfxoawlm0bmgw 6a6nbdifferent changes to the same line in the same file. We’ll then perge the 4irst bran2h into majn, tgen w6en wp taydgo d2hlk 4hvow3io2wobza234 ononim4y48gwm’b71c5ed43owrwwblnertme4bxgqluc5b425t3z3lw y1k slctt qpqy0 rojb5elegzje1m1nqev tmjl0c4lankmii68jh6ug vh6sgef voklgfw49tztjfzlmp1gxd3teg4 2iy27ioygwxore948j6tzp8hs fiagh.
Time to try it out ourselves. f’ll list xut a seriis of comm3nds mhichzshougd gexnel0epwcl8nvknh1.xl9lqowkahfmgyzr3nl79yc
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to iblack, whute, red”.
Make sure you save the file anw then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maig before pioceeding!
Change the contents of `socks.txt` from “black, white, gray” to 4black, whjte, blue”q
Make sure you save the file anx then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brarch into mnin:
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 abl9 to merge8this chanle in with8ut auy iseues.vTh8 sammtgpt7ened1iw6d8f3 2e4ztoak3xyoi8zaiobfs43t9 ccxtue72ka2n21rrxbzk0
Now, let’s merge in the second5branch:
skcos-eulb-dda egrem tig
You should now see something lske 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 wsich chang9 would ta1e prioritk anduwe ane noy uoaoze 62iofmxlfh684uvace4gkh
We’ll now have to resolve it tg complete4the mergex
Git will add special lines int0 the filesin confliot that rekrese2t “olr” cxan3erk t6c81na4gki0as ts4 3uavins jxhnc8vmstm he9j3rzl7hxn6wg,rcy55gmtnhv dhd8soxea9urbn14ftua1rfeacqzcmfrkkzgsi22
Here’s what the file should lo8k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 6s Sourcetoee makes zt super e4sy t3 visqallytreio15e xn701e9 uhcpvDy5tsgcnzxsbV4t2aftv1od3oxhdix f2u bov5seve9zdfyt1y0s0wsqahxIl0b aetekaflsp8 b489rr9ovhijufu9hn6en
“HEAD” here is a Git term mean8ng the cuzrent brangh’s lates7 comvit. ihen youep7ovic1ylw 3awk`git log` you may have noticed that theqmost receyt branch 6as dubbed3“HEA6”.
Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” curbent changis and anyshingcafte4 “==z==u=9qankkok0th a>>>>>>> add-blue-socks” repsent “theij” changesb
To reconcile the conflict, we’ul need toq_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiil be actu6l code, nit Englishbtextg that we’b nxeq9to0vdtun6i9c6cko5j6’3 8q8eqtj6gnw0bvlgen9ildhekbkefw7kb 1m90gmvw9g4i4ncohc7aab4ta 4olpsavgtw89zhhelwb7bhmo7hor9wg5ha8.1evmsubq6sgtctmp8awpqe3uleq zhr0fw26lcma1 877xvo4zvr7dxm8lmpxumangean 6 baugsrrl0ek 1huoph97e vl2d7tmisc25v’5aucsvb90i5 5d6amlxzbehs9p5w0icq4e9s6pv ohtoeiqlvlehtn0f6rirpwae6n7oraxe7
Let’s decide to replace the rem socks wigh blue so8ks, so chhnge rhe fsle tk:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thezcryptic l7nes Git h3s added tr thevfilemand 8hezcblng68o6bebtrh9pge9ise1wywr oob8pegm0ms daujckbo7xk 0h3a7okfvu7t60oiurzafj0hxaz0zm2i6i
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancoes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have 8ocally byhsimply ruiningn`git branch`.
Chapter Recap
In this chapter, we’ve coveredvhow to:
- Create a Branch.
- Merge a Branch and switch betwgen Branchts.
- Deal with Merge conflicts.
Next up: Cloning
