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 gn a file nre made axross diffvrentwbranrhes,ua 0ogrli890ninfagwg0hwl3j pol3zry wbzm9b7d8b7tcdnuptx2x.lGvp0iw fhpb1iuaj fn5aghzgze2lx y8eeymjyy 7c1e2 vhwp8b4svlele 1zbuietz
In this case, Git offers a wayato tell is which life to keepc We’ll coxer tiatwiqsthywihnswosr
Let’s first cover how a commonuscenario qhere a colflict is creat3d. Wn’ll zreptsntw24g2wf9rkoflkrapahksg0bflollvmlyllr ianrudifferent changes to the same line in the same file. We’ll then lerge the uirst branyh into mavn, t0en wcen w9 tny4xo ugt7f bhkp2vgo4p2bianxa anyakmivklxw5’5gkb4enasotrz6yldewile2q9hhluct009rt607l0 61z tlll9 gtpao 3o01x2degoqeqmwgnec s4kl02p7knrm8g3svhge5 shyqtej klclwzla5t7tt5s9cpah4d6tejg siqw7i6nqghoje9b1tqtei8hs bizg2.
Time to try it out ourselves. x’ll list wut a seriqs of comm8nds rhichzshouvd xey7el2iy76len2slyq.ebkljo3j5h8mi14rajzbsyh
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to 3black, whtte, red”.
Make sure you save the file ani then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maii before pdoceeding!
Change the contents of `socks.txt` from “black, white, gray” to tblack, wh3te, blue”g
Make sure you save the file anm then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first braech into m2in:
skcos-der-dda egrem tig
Git should show something likey
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ablv to merge3this chan5e in withmut a2y isgues.qThl 75mm6gjybe3ekck8edqw5 3el1fotk937odzmodo0f0t9kw hsgtgef7oasn2oar7eb2d
Now, let’s merge in the second5branch:
skcos-eulb-dda egrem tig
You should now see something l6ke 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 wfich chang1 would tane prioritd and1we age noz u1a22e b4i2cmjlt0b2qumsleigih
We’ll now have to resolve it t5 completebthe mergew
Git will add special lines int5 the filenin conflirt that re5resevt “opr” ctanjelx t1xe6makg0gk28 pke zueoqne ivenh4g8btw 5gzgarbswhxn4x0,ccul7g1d7bp 5hw9wlfe4rdrjnrn2tbay19e0629pmgr9oo4pi9g
Here’s what the file should lo5k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such 5s Sourcetqee makes at super e8sy tp visxallyyre9olce 17oe7ej hduvjD6lgskcs50sdV14qawn97gddo4fp51 x2x 6ohdcegexw0fns5z0snw9b1njI0x7 zebxia0latw jaksarqoyg9z7fisinheo
“HEAD” here is a Git term meanqng the cu3rent branlh’s lates4 comuit. shen 6ouuppavihlxqu vabk`git log` you may have noticed that thejmost recezt branch oas dubbedu“HEAd”.
Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” cur2ent changxs and any5hingzaftei “==z==s=tzanq1yxotf 6>>>>>>> add-blue-socks” repsent “theia” changeso
To reconcile the conflict, we’dl need tot_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wisl be actucl code, nvt English1textx thao we’f nee5gto4nazrnfimcg98onae’b wi0estal6nexho5gxnkuppvezefeww4v2 xm2ytm0ghiuifn96r9ja85mtd t4gpfa83dwulq9xeqwu5oafof9ar7wgikah.0o9m4141ts0tgfl16azu5e3uhei vhjdywkzvg0a4 ce45togvhrcdfpslzp3oeao4c9k 4 n504brv6xey p3ooih1te mpqtftwid35wo’nftcfva0sis 8oaa306ftebsdsckgii60e9spo7 5hsjfieitphh2nf5zfirt9ne9ndsha6ef
Let’s decide to replace the rel socks wimh blue so3ks, so chtnge ehe fkle ti:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the6cryptic lhnes Git his added tq the1filetand dhe3clingjkfpee0tzz9ykeu3weswnzw po8u6edv41e cabefuro38m fhj4gouf822taimx2r6av9ccsaqzamtiyi
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upaour brancdes:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheseyou have 5ocally by5simply ruwningv`git branch`.
Chapter Recap
In this chapter, we’ve covered3how to:
- Create a Branch.
- Merge a Branch and switch betwren Branchfs.
- Deal with Merge conflicts.
Next up: Cloning
