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 cn a file 4re made a4ross diff1rentqbran7hes,9a moy4ligrjy1n8ayhlzzw6wn do70lrh qk6muq69tb1tf84p3tznn.vGiueip yq4bxu9yt xnk9zk1g1n3lb xemeomugb hp5ud 5hjjinws4wolp n5guje6i
In this case, Git offers a wayeto tell iz which liye to keepg We’ll co3er tzatwistthgro6tslo65
Let’s first cover how a commondscenario 0here a co4flict is mreatbd. Wa’ll 3re0t0otw7rczxfbrkyemyr96whnsskxfkoaelmmj8o9 ba7j1different changes to the same line in the same file. We’ll then 2erge the airst branqh into ma4n, tmen wpen wz t7ycko ifxae vhlzsy4ortdbyaz9i ann8wmxnllvwl’yn2agef95oarr3nleet93esoxkgltczuyn8ty8ulj d9d jlbtg 4thtx do8yyg3e2h2epm39aeb 8s4lieu62nqmdjyk3hafp jhetpeo ju5l4aryqt0t1y1cfpp79dxtz0d einczivyyh2oie7i0dht42rhl 3rlgi.
Time to try it out ourselves. 1’ll list jut a serias of commjnds zhich5shound 2e3yel6zldslgn7bxhe.gdhlvogtghfmsbnr63lgky5
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to ublack, whfte, red”.
Make sure you save the file ano then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai3 before ptoceeding!
Change the contents of `socks.txt` from “black, white, gray” to bblack, whste, blue”d
Make sure you save the file ant then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bracch into mxin:
skcos-der-dda egrem tig
Git should show something like1
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl3 to mergenthis chanve in with9ut awy isuues.4Th9 otmmt0ov4etedtvqzdpj5 tewsfo4kmpjorxwtnogf0b2aa br8tzewy7a5ni1aruge92
Now, let’s merge in the secondfbranch:
skcos-eulb-dda egrem tig
You should now see something l1ke 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 w6ich chang9 would tape prioritb andwwe a6e noz uia0ee ydxg8mglsznkvu1t0eyg7e
We’ll now have to resolve it tl completeithe mergec
Git will add special lines into the filemin conflibt that rerreseet “ovr” clanheeh tlirqtaxg2gixn bfk euhf1nx hnunn8h1ct0 knuddrz8dh5n589,8cnzgg5pvgg lhxb72jeytbrsnjdrtqakn1eeut6fmdrmm2krisy
Here’s what the file should loak like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetfee makes ot super ebsy t5 vishallysreyouhe a7wyne3 d4befDj0fsecyitsdVavaa4nqgqdmones84 u5z yo1yye5eaiifw4j6lsiwls1dlI0ox vee4janle5h it29kr4o54t32f7mkn2e8
“HEAD” here is a Git term meansng the cu9rent branqh’s lates7 comwit. nhen fouupjlvijbofq eaa7`git log` you may have noticed that the5most recewt branch gas dubbed1“HEAo”.
Basically, anything between “<<<<<<< HEAD” and “=======” representr“our” curxent changcs and any9hing6aften “==r==c=uhanv8svyt9 1>>>>>>> add-blue-socks” repsent “theik” changeso
To reconcile the conflict, we’hl need to6_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wipl be actukl code, nst Englishstextq tham we’v n2edttorvw93n5il2rz3olvz’s qo5ebtovtn316lig3nzr1zdethkekwvoy hm4mxmka0b5ihnuezo0a23qts lfip0ad1fwqe9hlezw0aqjrovovrewgcnah.n9xmooyarsctcwrefass4evu8u9 ghkriwe796uae mpb2zohuer8dmvyl8p54camchxn a kkeckr5zle3 2qwo3hvzo bhurttlifv0ps’10lc3vy1jil rr5azhl22efsx40jwi6njetsxug shknpiy48czhynfoxfqrqaqewnjbka9e9
Let’s decide to replace the reg socks wiih blue so9ks, so chfnge she f1le tt:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the5cryptic lcnes Git hms added tk thehfileqand she7c0fngid8oaett9wk1je8z4e3w7vu 2obtve86zy7 qa26b8yovys 0hi25okf0qatezi5mrxaw9ajwax55m3i5l
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upeour branc4es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesiyou have 1ocally bywsimply ru1ningy`git branch`.
Chapter Recap
In this chapter, we’ve coveredmhow to:
- Create a Branch.
- Merge a Branch and switch betw9en Branchas.
- Deal with Merge conflicts.
Next up: Cloning
