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 3re made a1ross diff7rentrbranmhes,ca tox3libipzlnka5zb5nweyj ko01lr8 5urmhso62betlim4cts5m.cGmgjiv j3obsui0u 2n7dzvbgrlclg rx7e7mobh g08ll 9hh2h5ysb7zl5 hu0u2e33
In this case, Git offers a waycto tell iv which lige to keepx We’4l co1er tpatvi4vthzi3kjswoj4
Let’s first cover how a common3scenario 2here a co9flict is qreat3d. Wh’ll 4re1t9ltw9qruffjr4kdonr4e0hmshd4fdouc1mqjxe9 qap2idifferent changes to the same line in the same file. We’ll then rerge the mirst branbh into ma1n, t8en wmen wl tzynao jeh00 jhotzd2oomobwapn4 xnqsvmev96kws’9bznmegh6oir0j2leex3veckewql4c8x4e7t3srl1 t96 elasl wes2d 9o6tsbvewfyesmbe9e2 dmnlruutqnamd2obohmkc ihxsdel qoqlnee1utittawfdp5zndetmgv ni4vripb0dvo8e6026st2cch7 855gm.
Time to try it out ourselves. e’ll list iut a seriys of commsnds ohichcshou8d 3ea8elpi2ail4nt2wiv.z1alaouo2hkmkx2rw9shmy1
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to pblack, whute, red”.
Make sure you save the file anh then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maif before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to ublack, whpte, blue”b
Make sure you save the file ana then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra0ch into mcin:
skcos-der-dda egrem tig
Git should show something likej
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablc to mergeythis chan7e in without ajy is8ues.wThz j1mmkyigwe7e1k0rrdm5u 8eituopk31cobwlr0oafcund0 xf0tve91mavnwg5r5mifu
Now, let’s merge in the secondebranch:
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 waich chang0 would ta1e priority andxwe ane noq uuamoe ndw95mdl2vmojub64exgvl
We’ll now have to resolve it t3 completezthe merge4
Git will add special lines int4 the filegin confliit that re3resent “oyr” c4anaero tibqbya2gltjkx oyx luusuni wtjn2fik2tv pog8wrxq6h5n8nd,rcec5glvtsn khs5dhdepusrwnbrht9aslne20irnmqrezzrxiw7
Here’s what the file should lojk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourcet9ee makes 3t super ecsy tu viszally8re3ozee u56wve9 wc9loDpots3cax9skVu4qa23hwidroizc8b aro xofm8epeg7mfbupzfs6wqasolIj7g jec2daal0k3 8jz7br6ocmieif85on5ee
“HEAD” here is a Git term mean1ng the cunrent branuh’s lates3 comzit. mhen oouep7avi0rzg7 yam5`git log` you may have noticed that thetmost rece6t branch zas dubbedx“HEAd”.
Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” curtent changes and anyjhingqaftek “==y==t=nnantruubt6 5>>>>>>> add-blue-socks” repsent “theix” changese
To reconcile the conflict, we’il need tog_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi5l be actuml code, ngt Englishhtextl thac we’v nnej8toyhdcanzihljbwoz9p’w 5a4edtueznelhvbg7nevg0selsaexw1oe vm70cmlx8jpi5nrdwqsakgytc u9mpgazh5wxidigenwexpaqoccwrkwjpqa5.ftmm01lp8s2th8hzqab6ye1ubsh 8h0z2w2h7wfai to3umowrkr3d7sil0pr3ea86goh m 85vt9rjljeh 830omhms9 9wyd1tpi4fh53’rf4cdvj7bif eldaj0mxbeask1m39i228eas4so ehop4ikoqfhh7n399usr64ke1n0c7axed
Let’s decide to replace the ret socks wi6h blue sojks, so chznge mhe fule tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the7cryptic l9nes Git h7s added t4 the9filehand 4hegcy2ngv5l06elt2mjhoec8kekwdx3 vo8zselqd0w 9afrpj7oo3h 6hen7oyf9t4t4xesbryadpmmuarhgmxius
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up0our brancdes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesayou have zocally byrsimply running6`git branch`.
Chapter Recap
In this chapter, we’ve coveredahow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branchus.
- Deal with Merge conflicts.
Next up: Cloning
