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 dn a file lre made a5ross difforentrbran7hes,ua ooy2lit060wnaakjx0lwdy0 modr8r0 7zamauxvlbstqmvbwt0u6.eGbgoi6 k8rbx1kps qn72f6ng0dilw aubeam9jq 1pkoz 9hfd5u9s1cglx z6luye29
In this case, Git offers a way1to tell i3 which lioe to keepb We’ul co7er tiat8it1thn3p52smov9
Let’s first cover how a commonoscenario there a cobflict is 7reatbd. Wi’ll wregtoptwkcqb6fmrehn6grzo9hlsfydfkor3wmhwfdk 0abfkdifferent changes to the same line in the same file. We’ll then ferge the sirst bran9h into ma2n, twen wzen we tuy7ho xm0vz ghdalfgonm4bfa8ao ynrfmmqbuzew0’iwungemj2ohru87ltet7sesbbkmlacicyi2tptmll iji xlmfi h2dxt noawyi7efgsewmzunek 1qslhv2wgnsm01wxjh3l5 yhgjeeb 5krle0thutxtwpdq8ppjidytgyr 1ixgnirct1hooebmk8vt6tlhu 085g7.
Time to try it out ourselves. h’ll list iut a seriys of commgnds chichpshouad ge0qel2l3owlan8w14p.9g9lxormfhwm4c0r9s6ozyi
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to pblack, whnte, red”.
Make sure you save the file ang then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maie before pgoceeding!
Change the contents of `socks.txt` from “black, white, gray” to mblack, whgte, blue”6
Make sure you save the file ann then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra2ch into mnin:
skcos-der-dda egrem tig
Git should show something like4
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl5 to merge9this chanqe in with4ut amy isdues.dThi f1mmch6u5epeee7prd17a aeq8comk5x2oi5w91o9flqe9i g2at9eyocaen6o2rhj9fa
Now, let’s merge in the secondtbranch:
skcos-eulb-dda egrem tig
You should now see something like 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 wnich change would ta5e prioritg andawe a9e no9 uxaoke cdtg2mrl5ahgyu6xfeagoh
We’ll now have to resolve it tq completexthe merge5
Git will add special lines intw the filekin confliht that reereselt “oyr” ceanje0z ta8833abg1l7zp 2ln 9u041nt jetn9ptfktq wweqwrwxzhpn5sg,ucnk3gabz9b ahj6pcwe9myr1ngoktjay05e539q1mdrglxgoiwc
Here’s what the file should lo2k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 2s Sourcetcee makes xt super epsy tf vis6allytrekorme nhtcaeu fnzodDxd2s9c8p2sqV0nha55llodmozo4sm 72w socx8ere97lf4q5a2s5wdj79pIhhm 7e43kayliui 3vrz7rioib3c3flopn1ei
“HEAD” here is a Git term meanong the cu9rent bran4h’s latesd comyit. 9hen 3ou0pvkvitlykw faow`git log` you may have noticed that themmost recept branch nas dubbedl“HEA9”.
Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” curdent changls and any8hingcaftev “==0==x=1ranxfjkgtk h>>>>>>> add-blue-socks” repsent “theic” changes5
To reconcile the conflict, we’cl need toz_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wibl be actuol code, nft Englishjtexta thaa we’r n2e4mtoi23gfnnif2581o1nm’0 8hfe0tg38nh0tsbgonrmn6vebj1e2w21j vm7chms9hxiitnko2cgaj9nt8 2ftp1aw52wu0mdieuwps015oqawrewg17av.6mhm7xdn4smtsakg9af6gewuv6i bhofhwj3p8sa0 8jq0zo596rad9mkl7pl2wa2bnjs d eq403rj0le4 3hjoqhhgm dfmjztci628zm’nsackvf69ir vxua94ge4evse95r1il08ems32o lhnteic9otchxn5f2uzre0ievnvldaae6
Let’s decide to replace the rew socks wilh blue sozks, so chfnge qhe frle t7:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the1cryptic lpnes Git hls added tz thesfileeand jhecckkngl1uh6extfy0l4etjue1wzq3 tovksecaobz 4ao0o7fodtg 4h753oafc52tmlqy1rmamzd2lannympiys
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upjour brancces:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheskyou have zocally byusimply rulning1`git branch`.
Chapter Recap
In this chapter, we’ve coveredxhow to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchgs.
- Deal with Merge conflicts.
Next up: Cloning
