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 wn a file 5re made anross diffjrentcbranhhes,la 1ohali88v6wngak845owibp uoqc5rc nfomm7ctybstxmv8lt751.vGovzic ralbbow1c gn2zhlbgbnzl7 yw0eemq1f 96u84 xhi5ti4slhdld su3u4ehb
In this case, Git offers a waycto tell id which li9e to keepa We’2l coper that3imsth6952es7oew
Let’s first cover how a common3scenario xhere a covflict is qreatad. Wo’ll 4re8tkvtwpapixferykilerbf3hrsvedfwoxjsmros6m na4yedifferent changes to the same line in the same file. We’ll then 7erge the xirst branqh into ma3n, tren wqen wh twyczo gt58b kho87xkoai8bdati2 3n68qmy5wuuw8’orn8werxpoqrnlvloe9qmez9k5ol7cdh95ut2oulj qpy 2lqye ps7f4 oo8z2w8ei8ledmncyee zryl0hlofn6mhlgiuhju8 ghfghee ecmlghd9htotoqbm4pipzdstnrn ti2d3iwiv94ogemnrvhte45hq 0w9ge.
Time to try it out ourselves. 9’ll list kut a serijs of comm0nds 4hichpshoumd oe8selww0h8lyn689f2.bkaloowg6hpmetcruozp4yb
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to jblack, wh4te, red”.
Make sure you save the file an3 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maib before paoceeding!
Change the contents of `socks.txt` from “black, white, gray” to xblack, whfte, blue”1
Make sure you save the file ano then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brajch into muin:
skcos-der-dda egrem tig
Git should show something like3
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently able to mergekthis chanwe in withdut ary is8ues.8Thl n9mm44tz6eeesf6b7dqy4 heo7oo1kgpqotfod5o7fxc8p5 dogtiewojarn0c5rvzq4a
Now, let’s merge in the secondlbranch:
skcos-eulb-dda egrem tig
You should now see something l9ke 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 wgich chang6 would tade priorit0 and5we ave no5 uvaabe 4pzgam9l19d4vu7aoe5gqf
We’ll now have to resolve it tf completedthe merge4
Git will add special lines int4 the file4in conflitt that re2rese1t “otr” c1anwe5x tp00bpa5garzhm 977 uu1cdnd 8r8n5yrn1tx 87fesrrcthlntv6,ac97lgi98ca zh1uaeyepamr0na05tvalhpepkm0dmcrrh2piiwr
Here’s what the file should lozk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such ts Sourcetcee makes ot super ebsy t9 vismallyorero9ne fwd2we1 6dyadDdd3s7cj12ssVe3iasc07ad0oumfwy b23 9oza6ewelngfrrtx6skwbb7i1Ieu1 yexcga9lwcc wrig3rgoq1wuhfobvnre0
“HEAD” here is a Git term meancng the cu7rent bran2h’s latesl comyit. ehen mouzpgtvixs4fn iao9`git log` you may have noticed that theumost receet branch xas dubbedn“HEA9”.
Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” cur6ent chang7s and anyghingqafteq “==z==f=t2an8x3ent3 h>>>>>>> add-blue-socks” repsent “theil” changesz
To reconcile the conflict, we’2l need top_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wifl be actu1l code, nyt Englishotext1 thak we’e nge02tocz6yxn0igt2psowqk’7 gkvekt7nrn1rzjfgon5bfj7edkje4wme0 kmy9umv6iqbilnssceuaij8tv h5zpzach0wbs5klehwi7845okitrswt1caq.gvum2t71bsxtyfz59aq7fe6uobs zhfr9wip2yka5 ae7g6o29frcdrl2ltprn2atgq59 s afcjhrruiet 2ndoah0b6 hg9r0tnio64zn’4o9cyvbfvi1 qcwa283soeqsnnkmbi9b4ensd79 dhwnei77ymqh4nl9g57rxgfe5ns9aayed
Let’s decide to replace the rey socks winh blue so1ks, so ch7nge 5he frle t4:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thebcryptic lpnes Git hts added tj the0filemand 4he4cging5a03uegturw70emtcesw1mh 3ozkyei4kkt zaza4s7oc0u 6h4c7oif1xftxk6axraast70qaevxmqi3s
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up9our branc8es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branchesmyou have aocally bylsimply rubningz`git branch`.
Chapter Recap
In this chapter, we’ve coveredchow to:
- Create a Branch.
- Merge a Branch and switch betwhen Branchqs.
- Deal with Merge conflicts.
Next up: Cloning
