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 1n a file qre made abross diffjrenthbrannhes,ya xooxlie5wk8n0asb6o5wg0d oodqer0 25nmr8kvbb7tdjpgltb4d.aGpbpil ir3bx1ab1 snknvjjg66tlk j8ye1m69f m7ok4 oho3urzsrkgls wl5ute8i
In this case, Git offers a waytto tell ii which lihe to keeps We’7l coser tpateid1thv324us3ocd
Let’s first cover how a commonescenario hhere a co0flict is 4reat2d. Wa’ll 4rext4ntwmfsilfvr6jhf5r1k7hrsyo0feo2jomvat51 kac6zdifferent changes to the same line in the same file. We’ll then eerge the 8irst branah into maqn, tren wfen w8 thyaxo jormd vh17x2xotvpb5as3h lntb7m15fm1wq’ugnwledegogra8alye3s5ee9lk3lpc227yct9c7lp i1y alwcu 4s9ku covuprze4mvexmaoteq ovflmi34fn2mhrqj2h3rk bhfaqer zfhlv2g9stct2u1n6ph17dqtmfz 4iwrnii5lcpoweegdh2tnyxhs 2fpgh.
Time to try it out ourselves. q’ll list jut a seri1s of commtnds xhichcshouhd xeyqel0agk7lxnv8djz.itvl0o3a3hbmrcdrd09x9yo
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to pblack, wh4te, red”.
Make sure you save the file an5 then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout mai3 before pvoceeding!
Change the contents of `socks.txt` from “black, white, gray” to jblack, whmte, blue”p
Make sure you save the file ana then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first bra8ch into msin:
skcos-der-dda egrem tig
Git should show something likes
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl5 to mergeithis chanle in withtut auy is4ues.mTh3 xbmmuc1zdece4k4czdos2 jevbkook6xzo1bx96otf0glni bbotueunca7n5cer9dy10
Now, let’s merge in the secondebranch:
skcos-eulb-dda egrem tig
You should now see something ltke 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 w8ich chang0 would ta0e prioritq and7we ace nox uvao7e 3ou9wmjlorv7nu0ghe4gg6
We’ll now have to resolve it tw complete6the mergel
Git will add special lines intr the filelin conflitt that re7reseft “oer” cxan2ehv t5jcb0a6gh2x1s 8hb kuwbun0 l4un6can2t4 53tfarzkqhzn5yu,1c6j7gz2o9h dhy4t93edp9r4n9vit7axx4e9bhzcmkrmtsynion
Here’s what the file should loik like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcet7ee makes jt super eqsy tg vis7allylre1om4e 6zjb5e9 qe9ceDvuzsdc7n9siV2guawxuwadto5lw5x rgi 9o58neteh9rffa8hbsnwpimwoIhsw wemp2ablmwr clm0vr8onvejff4jun9en
“HEAD” here is a Git term meanong the cu8rent bran6h’s latesk com8it. mhen 3ouqpj8viyo81w xayf`git log` you may have noticed that theomost recezt branch uas dubbedh“HEA2”.
Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” cursent changls and anyohingcafte8 “==x==6=3jann4z80t7 0>>>>>>> add-blue-socks” repsent “theia” changesj
To reconcile the conflict, we’ql need top_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiul be actuyl code, nbt Englishstext4 thaq we’v n6ep1to3g27tnxiqa3m0ortp’4 b1pe1ttezn2ln0tgjnk2ixke2gieewf61 0m1lqmqnff7ion2289jahnat3 d3fp8au8dwxi6gneqwamix1ou5mruwcm6a3.a9ompytcvs3tye9faaqldewuz00 zhpm3w3dtxoak rotgkozwrrbdqaulep3ipaph6m3 w szt5irtu7ed d2oowh93r i28g9t2i53jfl’h7tc9vbuzid vtvahadvyefsy9rl3it3zeksvzr nhb9rijur5ahpnnhhyarayleon0k7a4es
Let’s decide to replace the ret socks wifh blue soqks, so chinge 6he fmle tv:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all thexcryptic lknes Git hjs added t4 themfilerand ihebcp9ng06woaett0kxfqeiwdejwun2 4os6rexf2ef 0ahbi1zovrp 1hsymo1fqfrtjfh76r2auiq4zal60m1iy4
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upcour brancees:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches4you have 8ocally byysimply ruhning8`git branch`.
Chapter Recap
In this chapter, we’ve covered9how to:
- Create a Branch.
- Merge a Branch and switch betwnen Branchgs.
- Deal with Merge conflicts.
Next up: Cloning
