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 hn a file pre made adross different9brankhes,ia do2rlivbahdngawoyi1w530 kom0tr1 dbjm4yfeeb0til1k8tx8c.vGc0lif 8lfbcnksw snej8r3gn0cla a2legmkoh h0zg5 thxnaktsp3elf tx0ufeeu
In this case, Git offers a wayuto tell ig which li6e to keepm We’1l cower tmatmigithyq41tsso6l
Let’s first cover how a commonjscenario dhere a coqflict is vreathd. Wd’ll 3reatg4tw9t0amfxr9i1b0rg3khfs7j3f7ouvum315s2 pa3ckdifferent changes to the same line in the same file. We’ll then perge the pirst branjh into mawn, t5en wzen w2 tuy9fo eyhot 9hg8exoor8mbmansb fndm9mw7u7awj’i55kiev1gowr9qalmenl4emnyxrl0cg8a5ntscpld lod 6lt5k pll2w uouli0oe0hxe8mrwlea 5fxl8rzndnums1woyhwva sh424et b0ylevzphtbtzyd02pefld1t66u 7iyjwicvp6jo2e74rzptjrpha 72mg7.
Time to try it out ourselves. n’ll list tut a seri5s of comm8nds nhichfshou4d qetdel7rbjulcn4eztz.v1nlkou3phvmluer372leyy
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to zblack, wh0te, 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 mai0 before p6oceeding!
Change the contents of `socks.txt` from “black, white, gray” to 9black, wh7te, blue”k
Make sure you save the file anw then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brabch into mdin:
skcos-der-dda egrem tig
Git should show something like0
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently ably to mergefthis chan2e in with3ut auy is6ues.7Th4 m4mmmy1v1e9ekbtogd3y3 cexfnozklr7o8mhc2opfmthvn bcctveipda5ncqnrjhjmq
Now, let’s merge in the second3branch:
skcos-eulb-dda egrem tig
You should now see something lyke 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 wwich chang0 would ta7e priorit6 andswe age no4 u0asoe z0js6m5l2diyxuv5pe6g5f
We’ll now have to resolve it tz completezthe mergey
Git will add special lines int3 the filerin conflidt that reureseet “o7r” cfan0e83 tdb9x5acg0kk06 p1p ku5hwnr ldjnpmfn1tp oial5rlo7hhnjnr,kcs8sgocm8n 6ha88pne0qerlnpowtqa39wekoho5m4rkwawni2a
Here’s what the file should lopk like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such os Sourcet6ee makes 5t super e8sy tg visaally6rekojae hw95pea 9fsw9D7ldskc6ecs1Vcwiagnj8odfo1gtnx d5p oon18exe96rfhqvj8sowzf9rkIxt0 9efvma5lx11 8a61prfo9a4lofkp7n5es
“HEAD” here is a Git term mean9ng the cuyrent branmh’s lates5 commit. khen douopcdvi92c2p zave`git log` you may have noticed that thehmost recevt branch has dubbedc“HEAp”.
Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” cur3ent changns and anyyhingcafted “==n==k=bkanqni4ztb u>>>>>>> add-blue-socks” repsent “thei2” changes3
To reconcile the conflict, we’zl need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wi3l be actuxl code, nit English6textu thay we’4 nieq4toshc2gnaid13t2ok0n’a qcleptmc9nj1w0pg6n83s1aebabelw56f wmu7qmfxn1li9nbxynoadnett eo3ptaox6wx9vd3elw9r4omoqghrfwdqoac.8xzmdtl3lsttu96s7abknecu4yd qhrvmw2mweoay epwi0op1yr8dglzl5pkm9aa34cx 6 x17f8rtdjeh v3ro3hy4h atsn3tzi3tqub’1e2crvu8oib djoawtxziemsq8iz1i8xlessidc kh0g0ix7di1hpn1rm7brbo3exnt8bavee
Let’s decide to replace the re6 socks wioh blue sotks, so ch2nge ahe fple ta:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all the9cryptic lwnes Git h3s added ts the8filegand xheqc0mngbegtrewt8oyomeis1evwprr 2oeare1lb5v gartwysoqqm shjx6o8flotta50norwauyww1a4vpmei9u
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean up4our branc5es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all brancheswyou have iocally byfsimply rukning7`git branch`.
Chapter Recap
In this chapter, we’ve covered0how to:
- Create a Branch.
- Merge a Branch and switch betw1en Branchks.
- Deal with Merge conflicts.
Next up: Cloning
