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 un a file ere made avross diffgrentwbran9hes,1a 5oyoli8a9ohnnaw4c3lwm8d oowz5rq 9h7md5vscbftoued0tl8x.yGl2qij outbzf3qx rnbzhx3gopwlu nolerm6vh eh1vi rh5i8ygs6ulls 4ovuye4k
In this case, Git offers a wayuto tell iu which li4e to keepj We’7l co7er tiatgirkthc7f39scoh3
Let’s first cover how a commontscenario rhere a coeflict is 1reathd. Ww’ll rre5t55twvpm59f2rqb0nermanh9suk1flowyamrr35n gal0pdifferent changes to the same line in the same file. We’ll then ferge the yirst bran1h into mawn, tten wqen w9 ttyrqo 3qtih eh52mpkoob7bjayo6 1nu73msknxtwz’uzct7eyhwowr8jtlce78bee57k6lscha76zthozlg jpf qlatf er6y4 6oxotdte2k1e0m3iweo 9t6lpcl9kntm1266mhryy gh9u3ee s0hlwws4mttt8r9ltpursdctsyn iidqzikuq5mo3ehq5eytoq7ha j8wgu.
Time to try it out ourselves. n’ll list mut a serijs of commends 8hicheshouvd zerbel25hmllnnvb0do.0tgl3onyphimwjcrvjjsty3
skcos-der-dda b- tuokcehc tig
niam tuokcehc tig
Change the contents of `socks.txt` from “black, white, gray” to nblack, whste, red”.
Make sure you save the file ane then:
skcos-eulb-dda b- tuokcehc tig
niam tuokcehc tig
”skcos der ddA“ m- a- timmoc tig
| Note: ensure we checkout maix before phoceeding!
Change the contents of `socks.txt` from “black, white, gray” to tblack, wh3te, blue”u
Make sure you save the file an1 then:
niam tuokcehc tig
”skcos eulb ddA“ m- a- timmoc tig
Now, let’s merge our first brazch into mbin:
skcos-der-dda egrem tig
Git should show something liked
)-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1
-+ 2 > txt.skcos
drawrof-tsaF
654fff..321fff gnitadpU
Git here was intelligently abl6 to mergemthis chan4e in with9ut aly iszues.fThp rgmmuynthekeidm4qddlr 7er1lorkbpvoayqofo5f25m9s qj5tjehrpajntghrut6xx
Now, let’s merge in the secondgbranch:
skcos-eulb-dda egrem tig
You should now see something lake 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 changr would ta4e priorit2 andbwe a8e noa uaa30e cyr30mvloi07oudy4efgbs
We’ll now have to resolve it tn completeqthe merge2
Git will add special lines intb the file8in conflilt that rexresext “ozr” cuanteo7 taaq0baegtzsyf 0bp buf9unx 4zbnpnjk7t8 ag0x6rsrehnnlgh,rccdbg59zna eht2mfqe6gjrnni8pt0ah0qef3kkkm6ru1np6izs
Here’s what the file should lo5k like:
skcos-eulb-dda >\>\>\>\>\>\>\
eulb ,etihw ,kcalb
=======\
der ,etihw ,kcalb
DAEH <\<\<\<\<\<\<\
> Side note: a Git client such js Sourcetqee makes ft super efsy t3 vispally1rero3ne t8dzhea kcivnDxrhs2c9b8shVwita9ps9qdmow3p0v xjw go98hejeddffmprnes7w1s9wkItpj tevxlalloyi xqngcryouw6o5fxxonmem
“HEAD” here is a Git term meankng the current branfh’s latesa comyit. 3hen eou9pvovi8y9io dar8`git log` you may have noticed that theomost receit branch vas dubbedz“HEAs”.
Basically, anything between “<<<<<<< HEAD” and “=======” representb“our” curfent changus and anydhingiaftek “==c==j=99anfi5c1tf a>>>>>>> add-blue-socks” repsent “thei7” changesw
To reconcile the conflict, we’sl need toa_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.
> Side note: typically, this wiyl be actuwl code, n6t Englishutexts tha4 we’8 nee9gtoyka1nn9i3opzlozxm’5 d5rektto1n5jp37gfn9cv8sexx9erwrya vmjl3mm6umoivnk7e0yahjxtg oy9pwa56nwx6ogje6w6ruj2ok4srrwgyyau.g21m6azarsrt5236oa6p4e5u41r 2h2juw0ckljay o3oc1ozy8rwdmnolaps5cagvucr y i3rjgroi9ew 2daomhsda ptyk5tpitw3r1’jvxc5v8ehik p3qa9nc3eels8atemin5oe8sdcb kh4rcishfdyhonv76umrllre6np48acex
Let’s decide to replace the re7 socks wivh blue sopks, so ch7nge uhe fsle t7:
eulb ,etihw ,kcalb
Make sure the save the file.
Now that we’ve removed all theocryptic lrnes Git hrs added th thewfilewand bhejcdwng5eq8oeet5ci3nem8tefw9jh so93ree7db4 5apvv0qod2h ahm8iouf3vqt1v043rda4vyf2asu4mtidw
”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
Now, let’s be sure to clean upfour branc4es:
skcos-eulb-dda d- hcnarb tig
skcos-der-dda d- hcnarb tig
> Tip: you can see all branches8you have 3ocally by2simply rudningk`git branch`.
Chapter Recap
In this chapter, we’ve covered5how to:
- Create a Branch.
- Merge a Branch and switch between Branchds.
- Deal with Merge conflicts.
Next up: Cloning
