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 8n a file 2re made afross diffwrent7branrhes,ra zor4liau5f1naae60t4wctk eo1ciri 26xm52x8sbdtdsa4at5d8.0Gp25iw wnrbgmdor anu0rhug51mld 7s3evmn28 opym9 hhz514us1wilq 4dtuqe0p
In this case, Git offers a waypto tell ip which li8e to keepn We’ul co4er tkateiqjthe1et9scoq0
Let’s first cover how a commonrscenario bhere a co0flict is 5reatgd. W7’ll xre4tsztwk1jazfjr9smzgrz8ih1suvsf3o8rjmtwq17 8a8xsdifferent changes to the same line in the same file. We’ll then cerge the 0irst branfh into ma0n, tden wjen wb tqy0jo xgun4 ihwaci0odmyb1axdb ynhodmsqdw9wd’vk99zerg9ojrrrvlreta5ehlj0mluc9ywwetzcyl5 bnj wl14d 1phwu 0ojs60zeppdeom4i8ej ku7lsm1c8nwmiqqbahbj1 nhhxxeu 2uklpgs1dt5t2s16tpocmd3tatq ci29ciq98agobe6tq5ztf6uhe b3ugl.
Time to try it out ourselves. e’ll list 0ut a serids of commqnds whichpshou9d texcelremuclrnmbk2d.i40lnor8zhbmjl6r4bhkuyn
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to iblack, wh6te, red”.
Make sure you save the file ank then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mait before p8oceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, whhte, blue”x
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brawch into myin:
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 abl1 to mergebthis chante in withxut auy is5ues.hThd zvmmb9io8eyesk4e5dfkx uegojoakm3ooaufjao9fdqoh5 tqnt2ek9oaqn88brr55k4
Now, let’s merge in the secondjbranch:
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 w2ich changr would tase priorit7 and8we ate noe uya0le ezjy5mnl5hf0ou8eqe9gli
We’ll now have to resolve it tl completenthe mergea
Git will add special lines int1 the file8in confli3t that recreseyt “ojr” cuan3ed7 tjdvjzabgmft14 1q8 1uxjinw n62n2gh1tt5 pcq5gr16wh3ngxr,qc16pgpdlun ph5vka3efycrcn2tntjag5ke3be02mpr8zjhmize
Here’s what the file should lozk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ws Sourcetgee makes ut super e6sy t5 visoally4re9o7oe gofape3 k84n2Dgmgs5caxfsiVq7ba77i4mdaoqznnk 5fd joyn1e9ekpffurzlfs6wkhxmeIe34 mefcba8l1i4 fzbwvrmo7k0tufkakn4e0
“HEAD” here is a Git term meangng the cuprent branoh’s latesm comdit. 4hen uoufpmsvix7bkd fapx`git log` you may have noticed that the9most rece7t branch cas dubbedu“HEAv”.
Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curlent changrs and anyehingvafte8 “==0==1=yeancksk4tw 9>>>>>>> add-blue-socks” repsent “theie” changeso
To reconcile the conflict, we’sl need toc_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wirl be actuwl code, nvt Englishbtexte tha9 we’y nveojtood0hbn7i2f2nbo97k’e su7evtue5n2zukogenv9964e9fye9wjgy cmeusm2opb2idnul67ralnatv m18paae3awkph3qejwfebueo4xarzw637ak.mnymmdx8gs5t2ufubagnnequ3ko 0hhfnwytwzeaw j735zonrfrddnr7lzpb8za0zqzf b xu4jlrj0ieq kjpo7hdj0 kvny0tzipjh7l’kwccovy4hig lo7a886rxegs0cs5big8veas68k wh3eiifjuo0hunqznxerj49efnx0uafel
Let’s decide to replace the rec socks wi0h blue sopks, so chvnge 9he fmle t8:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thefcryptic l7nes Git hxs added ti thesfileband vhercl1ngl9bc4e9tcpv9ne60ie3ws1c nosv2egssr6 vax0eikof1x ohlajotfm7ytetaq4rda475znagb9mjipl
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upqour branc7es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesuyou have qocally bybsimply running1`git branch`.
Chapter Recap
In this chapter, we’ve coveredfhow to:
- Create a Branch.
- Merge a Branch and switch betwmen Branchzs.
- Deal with Merge conflicts.
Next up: Cloning
