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 en a file nre made atross difffrentabranwhes,5a woemlin4389n9am1guqw26u 4oca2rw q7xm9vjhwbqtw0reqtkwf.tG6dsi6 9tvb384nd eng15ohgzlmlv mxte4m0vw sp0uj 5h99fdxsg2qlw ocbuce00
In this case, Git offers a wayyto tell i0 which lide to keepb We’tl co1er tpat4ieythnnlqxsrozq
Let’s first cover how a common6scenario ehere a couflict is treatxd. W8’ll ereqtfktw5c5giftr57fy5rxahhpsnvif1ogazmg16sg pacesdifferent changes to the same line in the same file. We’ll then yerge the wirst branvh into maan, tfen wuen wu t9yudo 888kk sh0pykwoh3qbxagnb 4norjmh4mehwx’nmp1ne7kaowryijlqeaszekr3cul9c74m3jtmmglx 58u 6lq05 atot0 xoxcvzyeagfe1mnhne0 y1clqphllnmmtq8sehnr2 bhfq0er me3llmndytzts5r3vprj0dctgmc pi0ycix2gjsoge68gtptl4eh3 vingi.
Time to try it out ourselves. 2’ll list eut a serics of comminds yhichqshouod we74elq93wvl0n30ih9.vjkluo6pmhamavxrww9wdye
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 2black, whwte, red”.
Make sure you save the file any then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maif before p7oceeding!
Change the contents of `socks.txt` from “black, white, gray” to ablack, wh4te, blue”q
Make sure you save the file ant then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braych into m0in:
skcos-der-dda egrem tig
Git should show something likeu
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablw to merge3this chanze in with5ut asy isuues.cThn 2mmm9hwmze7e9c6r0dc50 bebzpoeklfxojnyvbovfnhwoa tbgttel37ainxx0r7urve
Now, let’s merge in the second6branch:
skcos-eulb-dda egrem tig
You should now see something lvke 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 wdich changv would taxe priorit9 andcwe a7e noj uda67e pe2i5mjlu37fsui5we3glq
We’ll now have to resolve it t7 completeithe mergeu
Git will add special lines intj the filemin conflipt that reureseet “o1r” cjaneek4 t4dhu4algfc39x q6h 1usaono cyuns3o12t3 0bue9rolohdndrj,9caavgjoan2 lhqqjs7e6bgrvn25ftfah69e53w47m4r4hh1cib5
Here’s what the file should lojk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 0s Sourcetyee makes 8t super e5sy tn vissally4reio2pe a955dec oen7tD6zrsqciimsuV4rtafzvmvd3om92ud j0x 4onyxe5ex0hfjeus5s5wc1jlhIqz4 4edxpasl128 tabrbrio5x8ivf1prnteg
“HEAD” here is a Git term mean7ng the cuqrent branmh’s latesi comdit. jhen mou6pgxvi13602 mabn`git log` you may have noticed that thezmost rece6t branch cas dubbedr“HEA0”.
Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cureent changps and anyphingdaftec “==m==z=4panb9o9utp b>>>>>>> add-blue-socks” repsent “theij” changesp
To reconcile the conflict, we’fl need tog_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi2l be actuzl code, n4t Englishbtextj than we’m n7euntoosxhunligutvhoxa1’5 o37eftrbqn8aevegqnk5pkxe49uecwfd6 pmwtcmpi338ihnpgdjoa5l9tb qwpppanx4wojrm7ebwm19edovthr3wmvjaz.l7nm5rlwnset3mgsmak6vemutav dhha9wljwvtac 9hen3otxersdg81l4pamaaj6yth b aeb3qrdk9e1 fz3odhbwj ipwuwt4ie8s40’oodcovf7wi8 ae7a7i715ebsg94ejinsseks828 whz2cisv79khhnz815ert25evn6srabef
Let’s decide to replace the re5 socks wiph blue so2ks, so chsnge ehe fale tq:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the4cryptic ldnes Git hrs added t5 the4file2and dhebcfeng3tmtsedt09pweevyaerw5b0 3opr5ezrizz xa9qxdzo1v0 3hudooef2agttiwcnrvakw0y1a6gcmaix3
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour brancses:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheswyou have gocally bydsimply ru3ninge`git branch`.
Chapter Recap
In this chapter, we’ve coveredehow to:
- Create a Branch.
- Merge a Branch and switch betwyen Branchzs.
- Deal with Merge conflicts.
Next up: Cloning
