爱问 爱问共享资料 爱问分类
首页 > > > 程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using…

程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using Subversion.pdf

程序员修炼三部曲.版本控制之道.Pragmatic Versi…

上传者: Jason
639次下载 0人收藏 暂无简介 简介 2012-01-05 举报

简介:程序员修炼系列

WhatreadersaresayingaboutPragmaticVersionControlusingSubversionIexpectedalot,butyousurprisedmewithevenmore.Hav-ingusedCVSforyearsIhesitatedtotrySubversionuntilnow,althoughIknewitwouldsolvemanyoftheshortcom-ingsofCVS.Afterreadingyourbook,myexcusestostaywithCVSdisappeared.Oh,andcomingfromthePragmaticBookshelfthisbookisfuntoreadtoo.ThanksMike.SteffenGemkowManagingDirector,ObjectFabGmbHI’malong-timeuserofCVSandI’vebeenskepticalofSub-version,wonderingifitwouldeverbe“readyforprimetime.”Untilnow.ThankstoMikeMasonforwritingaclear,con-cise,gentleintroductiontothisnewtool.Afterreadingthisbook,I’mactuallyexcitedaboutthepossibilitiesforversioncontrolthatSubversionbringstothetable.DavidRuppSeniorSoftwareEngineer,Great-WestLife&AnnuityThiswasexactlytheSubversionbookIwaswaitingfor.Asalong-timePerforceandCVSuserandadministrator,andinmyroleasanagiletoolscoach,IwantedacompactbookthattoldmejustwhatIneededtoknow.Thisisit.WithinacoupleofhoursIwasupandrunningagainstremoteSubversionservers,andsettingupmyownlocalserverstoo.Mikeusesalotofcommand-lineexamplestoguidethereader,andasaWindowsuserIwasworriedatfirst.Myfearswereunfoundedthough—Mike’sexamplesweresoclearthatIthinkI’llsticktousingthecommandlinefromnowon!IthoroughlyrecommendthisbooktoanyonegettingstartedusingoradministeringSubversion.MikeRobertsProjectco-Lead,CruiseControl.NETPragmaticVersionControlusingSubversionMikeMasonThePragmaticBookshelfRaleigh,NorthCarolinaDallas,TexasManyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andThePragmaticProgrammers,LLCwasawareofatrademarkclaim,thedesignationshavebeenprintedininitialcapitallettersorinallcapitals.ThePragmaticStarterKit,ThePragmaticProgrammer,PragmaticProgramming,PragmaticBookshelfandthelinkinggdevicearetrademarksofThePragmaticProgrammers,LLC.Everyprecautionwastakeninthepreparationofthisbook.However,thepublisherassumesnoresponsibilityforerrorsoromissions,orfordamagesthatmayresultfromtheuseofinformation(includingprogramlistings)con-tainedherein.OurPragmaticcourses,workshops,andotherproductscanhelpyouandyourteamcreatebettersoftwareandhavemorefun.Formoreinformation,aswellasthelatestPragmatictitles,pleasevisitusathttp://www.pragmaticprogrammer.comCopyright2005ThePragmaticProgrammersLLC.Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,inanyform,orbyanymeans,electronic,mechanical,photo-copying,recording,orotherwise,withoutthepriorconsentofthepublisher.PrintedintheUnitedStatesofAmerica.ISBN0-9745140-6-3Printedonacid-freepaperwith85%recycled,30%post-consumercontent.Firstprinting,February2005Version:2005-2-3ContentsPrefaceviii1Introduction11.1VersionControlinAction.............21.2RoadMap......................61.3WhyChooseSubversion..............62WhatIsVersionControl?92.1TheRepository...................92.2WhatShouldWeStore?..............112.3WorkingCopiesandManipulatingFiles.....122.4Projects,Directories,andFiles..........152.5WhereDoVersionsComeIn?...........162.6Tags.........................182.7Branches......................192.8Merging.......................222.9LockingOptions..................232.10ConfigurationManagement(CM).........263GettingStartedwithSubversion273.1InstallingSubversion...............273.2CreatingaRepository...............323.3CreatingaSimpleProject.............333.4StartingtoWorkwithaProject..........363.5MakingChanges..................383.6UpdatingtheRepository..............393.7WhenWorldsCollide................433.8ConflictResolution.................45CONTENTSvi4HowTo...504.1OurBasicPhilosophy...............514.2ImportantStepsWhenUsingVersionControl.515AccessingaRepository535.1NetworkProtocols.................535.2ChoosingaNetworkingOption..........586CommonSubversionCommands606.1CheckingThingsOut...............606.2KeepingUp-to-Date................626.3AddingFilesandDirectories...........646.4Properties......................646.5CopyingandMovingFilesandDirectories...736.6SeeingWhatHasChanged............786.7HandlingMergeConflicts.............846.8CommittingChanges...............896.9ExaminingChangeHistory............896.10RemovingaChange................937OrganizingYourRepository977.1ASimpleProject..................977.2MultipleProjects..................987.3MultipleRepositories...............998UsingTagsandBranches1018.1TagsandBranches.................1028.2CreatingaReleaseBranch............1058.3WorkinginaReleaseBranch...........1078.4GeneratingaRelease...............1098.5FixingBugsinaReleaseBranch.........1118.6DeveloperExperimentalBranches........1148.7WorkingwithExperimentalCode........1168.8MergingtheExperimentalBranch........1169CreatingaProject1189.1CreatingtheInitialProject............1199.2StructurewithintheProject...........1219.3SharingCodebetweenProjects..........125PreparedexclusivelyforKimPartridgeCONTENTSvii10Third-PartyCode13110.1BinaryLibraries..................13110.2LibrarieswithSourceCode............13410.3KeywordExpansionduringImports.......140AInstall,Network,Secure,andAdminister141A.1InstallingSubversion...............141A.2Networkingwithsvnserve.............142A.3Networkingwithsvn+ssh.............144A.4NetworkingwithApache..............147A.5SecuringSubversion................153A.6BackingUpYourRepository...........158BMigratingtoSubversion162B.1Gettingcvs2svn...................163B.2ChoosingHowMuchtoConvert.........163B.3ConvertingYourRepository............164CThird-PartySubversionTools166C.1TortoiseSVN.....................166C.2IDEIntegration...................173C.3OtherTools.....................174DCommandSummaryandRecipes176D.1SubversionCommandSummary.........176D.2Recipes.......................186EOtherResources192E.1OnlineResources..................192E.2Bibliography....................193PreparedexclusivelyforKimPartridgePrefaceIwasprettyexcitedwhenIheardaboutthePragmaticStarterKit—finallysomeguidanceonthebasicstuffallprojectsneedtogetright.TheopportunitytoproduceaSubversioneditionofPragmaticVersionControlwasoneIcouldn’tmiss.Sub-versionhadpreviouslysavedme(andmyteam)fromversioncontrolhell,andIwantedtodomyparttohelppromoteagreatnewversioncontrolsystem.Versioncontroladdsanimmenseamounttoaproject.Itgivesyouasafetynet,helpsyourteamcollaborateeffectively,letsyouorganizeyourbuildsandQA,andevenallowsyoutodosomedetectiveworkifthingsgowrong.IhopethisneweditionofPragmaticVersionControlwillhelpyouandyourteamgetstartedandsucceedwithSubversion.AcknowledgmentsI’dliketothankDaveandAndyfortakingachanceonmebeingabletowritethebookandtothankDavebeingsuchanexcellenteditor.Iwasn’treallysurewhatIwasgettingmyselfinto,andDave’sadviceandguidancewereinvaluable.Thebookreceivedplentyofscrutinybyreviewers;I’dliketothankBradAppleton,BrankoCˇibej,MartinFowler,SteffenGemkow,RobertRasmussen,MikeRoberts,andDavidRuppfortheirwell-thought-outcommentsandsuggestions.I’mfranklyamazedbythequalityoffeedbackIgot—greatsugges-tions,highlytechnicalcommentsandplentyofpeoplethink-ingaboutthe“biggerpicture.”EveryoneatThoughtWorkshasbeenreallysupportiveofmybookwritingefforts,includingseveralpeoplewhotookthetimetolookthroughearlydraftsofthebook,andI’dliketoPREFACEixthankallthosewhogavemeadviceandguidance.I’dparticu-larlyliketothanktheCalgaryofficeforwelcomingmeintothefoldthisyearandforenablingmetogetstufffinishedwhenthecrunchpointcame.FinallyI’dliketothankMartin,Mike,andMichelleformakingmebelieveIcouldreallywritethebookandfortheirencour-agementalongtheway.MikeMasonDecember2004mike@mikemason.caTypographicConventionsitalicfontItalicsindicateatermthatisbeingdefined,orborrowedfromanotherlanguage.filesFiles(anddirectories)areindicatedlikethis.commandsCommands(andoptionssuchas-h)areshownlikethis.outputOutput(aswellasthingsyoumightneedtotype)isindicatedlikethis.Ifcommandsaretoolongforasinglelinethey’resplitontomultiplelinesusinga\(backwardslash).CVSHint:Thiskindoftextindicatesahintforusersfamil-iarwithCVS.Thiswarningsignindicatesthismaterialismoreadvancedandcanbeskippedonyourfirstread-ing.“Joethedeveloper,”ourcartoonfriend,asksarelatedquestionthatyoumayfinduseful.PreparedexclusivelyforKimPartridgeChapter1IntroductionThisbooktellsyouhowtoimprovetheeffectivenessofyoursoftwaredevelopmentprocessusingversioncontrol.Versioncontrol,sometimescalledsourcecodecontrol,isthefirstlegofourprojectsupporttripod.Weviewtheuseofversioncontrolasmandatoryonallprojects.Versioncontroloffersmanyadvantagestobothteamsandindividuals:•Itgivestheteamaproject-wideundobutton;nothingisfinal,andmistakesareeasilyrolledback.Imagineyou’reusingtheworld’smostsophisticatedwordprocessor.Ithaseveryfunctionimaginable,exceptone.Forsomerea-son,theyforgottoaddsupportforaDELETEkey.Thinkhowcarefullyandslowlyyou’dhavetotype,particularlyasyougotneartheendofalargedocument.Onemis-take,andyou’dhavetostartagain.It’sthesamewithversioncontrol;havingtheabilitytogobackanhour,aday,oraweekfreesyourteamtoworkquickly,confidentthattheyhaveawayoffixingmistakes.•Itallowsmultipledeveloperstoworkonthesamecodebaseinacontrolledmanner.Theteamnolongerloseschangeswhensomeoneoverwritestheeditsmadebyanotherteammember.•Theversioncontrolsystemkeepsarecordofthechangesmadeovertime.Ifyoucomeacrosssome“surprisingcode,”it’seasytofindoutwhomadethechange,when,and(withanyluck)why.VERSIONCONTROLINACTION2•Aversioncontrolsystemallowsyoutosupportmultiplereleasesofyoursoftwareatthesametimeasyoucon-tinuewiththemainlineofdevelopment.Withaversioncontrolsystem,there’snolongeraneedfortheteamtostopworkduringacodefreezejustbeforerelease.•Versioncontrolisaproject-widetimemachine,allowingyoutodialinadateandseeexactlywhattheprojectlookedlikeonthatdate.Thisisusefulforresearch,butitisessentialforregeneratingpriorreleasesforcus-tomerswithproblems.Thisbookfocusesonversioncontrolfromaprojectperspec-tive.Ratherthansimplylistingthecommandsavailableinaversioncontrolsystem,weexplainthetasksyouneedtoper-formwellinasuccessfulprojectandthenshowhowaversioncontrolsystemcanhelp.Let’sstartwithasmallstory....1.1VersionControlinActionFredrollsintotheofficeeagertocontinueworkingonthenewOrinocobookorderingsystem.(WhyOrinoco?Fred’scom-panyusesthenamesofriversforallinternalprojects.)Aftergettinghisfirstcupofcoffee,Fredupdateshislocalcopyoftheproject’ssourcecodewiththelatestversionsfromthecen-tralversioncontrolsystem.Inthelogthatliststheupdatedfiles,henoticesthatWilmahaschangedcodeinthebasicOrdersclass.Fredgetsworriedthatthischangemightaffecthiswork,buttodayWilmaisoffattheclient’ssite,installingthelatestrelease,sohecan’taskherdirectly.Instead,Fredaskstheversioncontrolsystemtodisplaythenotesassoci-atedwiththechangetoOrders.Wilma’scommentdoeslittletoreassurehim:AddednewdeliveryPreferencesfieldtotheOrdersclassTofindoutwhat’sgoingon,hegoesbacktotheversioncon-trolsystemandaskstoseetheactualchangesmadetothesourcefile.HeseesthatWilmahasaddedacoupleofinstancevariables,buttheyaresettodefaultvalues,andnothingseemstochangethem.Thismightbeaprobleminthefuture,butitisnothingthatwillstophimtoday,soFredcontinuesworking.PreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION3Asheworksonhiscode,Fredaddsanewclassandacou-pleoftestclassestothesystem.Fredaddsthenamesofthefileshecreatestotheversioncontrolsystemashecreatesthem;thefilesthemselveswon’tbeaddeduntilhecommitshischanges,butaddingtheirnamesnowmeanshewon’tfor-gettoaddthemlater.Acoupleofhoursintotheday,Fredhascompletedthefirstpartofsomenewfunctionality.Itpassesitstests,anditwon’taffectanythingintherestofthesystem,sohedecidestocheckitallintotheversioncontrolsystem,makingitavailabletotherestoftheteam.Overtheyears,Fredhasfoundthatcheckingcodeinandoutfrequentlyworksbestforhim:it’saloteasiertoreconciletheoccasionalconflictifyouhavetoworryaboutonlyacoupleoffilesratherthanaweek’sworthofchangesfromthewholeteam.WhyYouShouldNeverAnswerthePhoneJustasFredisabouttostartthenextroundofcoding,hisphonerings.It’sWilma,callingfromtheclient’ssite.Itlookslikethere’sabuginthereleasesheisinstalling:printedinvoicesarenotcalculatingsalestaxonshippingamounts.Theclientisgoingballistic,andtheyneedafixnow....UnlessYouUseVersionControlFreddouble-checksthenameofthereleasewithWilmaandthentellstheversioncontrolsystemtocheckoutallthefilesinthatversionofthesoftware.HeputsitinatemporarydirectoryonhisPC,asheintendstodeleteitafterhefinishesthework.Henowhastwocopiesofthesystem’ssourcecodeonhiscomputer:thetrunk(themainlineofdevelopment)andtheversionreleasedtotheclient.Becauseheisabouttofixabug,hetellstheversioncontrolsystemtotaghissourcecodewithalabel.(He’lladdanothertagwhenhehasfixedthebug.Thesetagsactasflagsyouleavebehindtomarksignificantpointsinthedevelopment.Byusingconsistentlynamedtagsbeforeandafterhemakesthechange,otherfolksinhisteamwillbeabletoseeexactlywhatchangedshouldtheylookatitlater.)PreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION4Inordertoisolatetheproblem,Fredfirstwritesatest.Sureenough,itlookslikenooneevercheckedthesalestaxcal-culationwhenshippingwasinvolved,becausehistestimme-diatelyshowstheproblem.(Fredmakesanotetoraisethisduringthisiteration’sreviewmeeting;thisissomethingthatshouldneverhavegoneoutthedoor.)Sighing,Fredaddsthelineofcodethataddsshippingtothetaxabletotal,com-piles,andchecksthathistestpasses.Hererunsthewholetestsuiteasaquicksanitytestandchecksthefixedcodebackintothecentralversioncontrolsystem.Finally,hetagsthereleasebranchindicatingthatthebugisfixed.HesendsanoteofftoQA,whoisresponsibleforshippingemergencyreleasestotheclient.Usinghistag,they’llbeabletoinstructthebuildsystemtoproduceadeliverydiskthatincludeshisfix.FredthenphonesWilmaandtellsherthefixisinthehandsofQAandshouldbewithhersoon.Havingfinishedwiththislittledistraction,Fredremovesthesourceforthereleasedcodefromhislocalmachine:there’snopointinclutteringthingsup,andthechangeshehasmadearesafelytuckedbackintothecentralserver.Hethengetstowondering:isthesalestaxbughefoundinthereleasedcodealsopresentinthecurrentdevelopmentversion?Thequick-estwaytocheckistoaddthetesthewroteinthereleasedver-siontothedevelopmenttestsuite.Hetellstheversioncontrolsystemtomergethatparticularchangeinthereleasebranchintotheappropriatefileinthedevelopmentcopy.Themergeprocesstakeswhateverchangesweremadetothereleasefilesandmakesthesamechangestothedevelopmentver-sion.Whenherunsthetests,hisnewtestfails:thebugisindeedpresent.Hethenmoveshisfixfromthereleasebranchintothedevelopmentversion.(Hedoesn’tneedthereleasebranch’scodeonhismachinetodoanyofthis;allthechangesarebeingfetchedfromthecentralversioncontrolsystem.)Oncehehasthetestsallrunningagain,hecommitsthischangeintotheversioncontrolsystem.That’sonelessbugthat’llbitetheteamnexttime.Crisisover,Fredgetsbacktoworkingonhisowntasksfortheday.Hespendsahappyafternoonwritingtestsandcodeandtowardtheendofthedaydecidesheisdone.Whilehehasbeenworking,otherfolksinhisteamhavealsobeenmakingPreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION5changes,soheusestheversioncontrolsystemtotaketheirworkandapplyithislocalcopyofthesource.Herunsthetestsonelasttimeandthencheckshischangesbackin,readytostartworkthenextday.Tomorrow...Unfortunately,thenextdaybringsitsownsurprises.Over-nightFred’scentralheatingfinallygivesuptheghost.AsFredlivesinMinnesota,andasit’sFebruary,thisisn’tsomethingtobetakenlightly.Fredcallsintoworktosayhe’llbeoutmostofthedaywaitingfortherepairfolkstoarrive.However,thatdoesn’tmeanhehastostopworking.AccessinghisofficenetworkusingasecureconnectionoverthepublicInternet,Fredchecksoutthelatestdevelopmentcodeontohislaptop.Becausehecheckedinbeforehewenthomethepreviousnight,everythingisthereandup-to-date.Hecon-tinuestoworkathome,wrappedinablanketandsittingbythefire.Beforehestopsfortheday,hecheckshischangesinfromthelaptopsothey’llbeavailabletohimatworkthenextday.Lifeisgood(exceptfortheheatingrepairbill).

程序员修炼三部曲.版本控制之道.Pragmatic Version Control Using Subversion.pdf

程序员修炼三部曲.版本控制之道.Pragmatic Versi…

上传者: Jason
639次下载 0人收藏 暂无简介 简介 2012-01-05 举报

简介:程序员修炼系列

WhatreadersaresayingaboutPragmaticVersionControlusingSubversionIexpectedalot,butyousurprisedmewithevenmore.Hav-ingusedCVSforyearsIhesitatedtotrySubversionuntilnow,althoughIknewitwouldsolvemanyoftheshortcom-ingsofCVS.Afterreadingyourbook,myexcusestostaywithCVSdisappeared.Oh,andcomingfromthePragmaticBookshelfthisbookisfuntoreadtoo.ThanksMike.SteffenGemkowManagingDirector,ObjectFabGmbHI’malong-timeuserofCVSandI’vebeenskepticalofSub-version,wonderingifitwouldeverbe“readyforprimetime.”Untilnow.ThankstoMikeMasonforwritingaclear,con-cise,gentleintroductiontothisnewtool.Afterreadingthisbook,I’mactuallyexcitedaboutthepossibilitiesforversioncontrolthatSubversionbringstothetable.DavidRuppSeniorSoftwareEngineer,Great-WestLife&AnnuityThiswasexactlytheSubversionbookIwaswaitingfor.Asalong-timePerforceandCVSuserandadministrator,andinmyroleasanagiletoolscoach,IwantedacompactbookthattoldmejustwhatIneededtoknow.Thisisit.WithinacoupleofhoursIwasupandrunningagainstremoteSubversionservers,andsettingupmyownlocalserverstoo.Mikeusesalotofcommand-lineexamplestoguidethereader,andasaWindowsuserIwasworriedatfirst.Myfearswereunfoundedthough—Mike’sexamplesweresoclearthatIthinkI’llsticktousingthecommandlinefromnowon!IthoroughlyrecommendthisbooktoanyonegettingstartedusingoradministeringSubversion.MikeRobertsProjectco-Lead,CruiseControl.NETPragmaticVersionControlusingSubversionMikeMasonThePragmaticBookshelfRaleigh,NorthCarolinaDallas,TexasManyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedastrademarks.Wherethosedesignationsappearinthisbook,andThePragmaticProgrammers,LLCwasawareofatrademarkclaim,thedesignationshavebeenprintedininitialcapitallettersorinallcapitals.ThePragmaticStarterKit,ThePragmaticProgrammer,PragmaticProgramming,PragmaticBookshelfandthelinkinggdevicearetrademarksofThePragmaticProgrammers,LLC.Everyprecautionwastakeninthepreparationofthisbook.However,thepublisherassumesnoresponsibilityforerrorsoromissions,orfordamagesthatmayresultfromtheuseofinformation(includingprogramlistings)con-tainedherein.OurPragmaticcourses,workshops,andotherproductscanhelpyouandyourteamcreatebettersoftwareandhavemorefun.Formoreinformation,aswellasthelatestPragmatictitles,pleasevisitusathttp://www.pragmaticprogrammer.comCopyright2005ThePragmaticProgrammersLLC.Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,inanyform,orbyanymeans,electronic,mechanical,photo-copying,recording,orotherwise,withoutthepriorconsentofthepublisher.PrintedintheUnitedStatesofAmerica.ISBN0-9745140-6-3Printedonacid-freepaperwith85%recycled,30%post-consumercontent.Firstprinting,February2005Version:2005-2-3ContentsPrefaceviii1Introduction11.1VersionControlinAction.............21.2RoadMap......................61.3WhyChooseSubversion..............62WhatIsVersionControl?92.1TheRepository...................92.2WhatShouldWeStore?..............112.3WorkingCopiesandManipulatingFiles.....122.4Projects,Directories,andFiles..........152.5WhereDoVersionsComeIn?...........162.6Tags.........................182.7Branches......................192.8Merging.......................222.9LockingOptions..................232.10ConfigurationManagement(CM).........263GettingStartedwithSubversion273.1InstallingSubversion...............273.2CreatingaRepository...............323.3CreatingaSimpleProject.............333.4StartingtoWorkwithaProject..........363.5MakingChanges..................383.6UpdatingtheRepository..............393.7WhenWorldsCollide................433.8ConflictResolution.................45CONTENTSvi4HowTo...504.1OurBasicPhilosophy...............514.2ImportantStepsWhenUsingVersionControl.515AccessingaRepository535.1NetworkProtocols.................535.2ChoosingaNetworkingOption..........586CommonSubversionCommands606.1CheckingThingsOut...............606.2KeepingUp-to-Date................626.3AddingFilesandDirectories...........646.4Properties......................646.5CopyingandMovingFilesandDirectories...736.6SeeingWhatHasChanged............786.7HandlingMergeConflicts.............846.8CommittingChanges...............896.9ExaminingChangeHistory............896.10RemovingaChange................937OrganizingYourRepository977.1ASimpleProject..................977.2MultipleProjects..................987.3MultipleRepositories...............998UsingTagsandBranches1018.1TagsandBranches.................1028.2CreatingaReleaseBranch............1058.3WorkinginaReleaseBranch...........1078.4GeneratingaRelease...............1098.5FixingBugsinaReleaseBranch.........1118.6DeveloperExperimentalBranches........1148.7WorkingwithExperimentalCode........1168.8MergingtheExperimentalBranch........1169CreatingaProject1189.1CreatingtheInitialProject............1199.2StructurewithintheProject...........1219.3SharingCodebetweenProjects..........125PreparedexclusivelyforKimPartridgeCONTENTSvii10Third-PartyCode13110.1BinaryLibraries..................13110.2LibrarieswithSourceCode............13410.3KeywordExpansionduringImports.......140AInstall,Network,Secure,andAdminister141A.1InstallingSubversion...............141A.2Networkingwithsvnserve.............142A.3Networkingwithsvn+ssh.............144A.4NetworkingwithApache..............147A.5SecuringSubversion................153A.6BackingUpYourRepository...........158BMigratingtoSubversion162B.1Gettingcvs2svn...................163B.2ChoosingHowMuchtoConvert.........163B.3ConvertingYourRepository............164CThird-PartySubversionTools166C.1TortoiseSVN.....................166C.2IDEIntegration...................173C.3OtherTools.....................174DCommandSummaryandRecipes176D.1SubversionCommandSummary.........176D.2Recipes.......................186EOtherResources192E.1OnlineResources..................192E.2Bibliography....................193PreparedexclusivelyforKimPartridgePrefaceIwasprettyexcitedwhenIheardaboutthePragmaticStarterKit—finallysomeguidanceonthebasicstuffallprojectsneedtogetright.TheopportunitytoproduceaSubversioneditionofPragmaticVersionControlwasoneIcouldn’tmiss.Sub-versionhadpreviouslysavedme(andmyteam)fromversioncontrolhell,andIwantedtodomyparttohelppromoteagreatnewversioncontrolsystem.Versioncontroladdsanimmenseamounttoaproject.Itgivesyouasafetynet,helpsyourteamcollaborateeffectively,letsyouorganizeyourbuildsandQA,andevenallowsyoutodosomedetectiveworkifthingsgowrong.IhopethisneweditionofPragmaticVersionControlwillhelpyouandyourteamgetstartedandsucceedwithSubversion.AcknowledgmentsI’dliketothankDaveandAndyfortakingachanceonmebeingabletowritethebookandtothankDavebeingsuchanexcellenteditor.Iwasn’treallysurewhatIwasgettingmyselfinto,andDave’sadviceandguidancewereinvaluable.Thebookreceivedplentyofscrutinybyreviewers;I’dliketothankBradAppleton,BrankoCˇibej,MartinFowler,SteffenGemkow,RobertRasmussen,MikeRoberts,andDavidRuppfortheirwell-thought-outcommentsandsuggestions.I’mfranklyamazedbythequalityoffeedbackIgot—greatsugges-tions,highlytechnicalcommentsandplentyofpeoplethink-ingaboutthe“biggerpicture.”EveryoneatThoughtWorkshasbeenreallysupportiveofmybookwritingefforts,includingseveralpeoplewhotookthetimetolookthroughearlydraftsofthebook,andI’dliketoPREFACEixthankallthosewhogavemeadviceandguidance.I’dparticu-larlyliketothanktheCalgaryofficeforwelcomingmeintothefoldthisyearandforenablingmetogetstufffinishedwhenthecrunchpointcame.FinallyI’dliketothankMartin,Mike,andMichelleformakingmebelieveIcouldreallywritethebookandfortheirencour-agementalongtheway.MikeMasonDecember2004mike@mikemason.caTypographicConventionsitalicfontItalicsindicateatermthatisbeingdefined,orborrowedfromanotherlanguage.filesFiles(anddirectories)areindicatedlikethis.commandsCommands(andoptionssuchas-h)areshownlikethis.outputOutput(aswellasthingsyoumightneedtotype)isindicatedlikethis.Ifcommandsaretoolongforasinglelinethey’resplitontomultiplelinesusinga\(backwardslash).CVSHint:Thiskindoftextindicatesahintforusersfamil-iarwithCVS.Thiswarningsignindicatesthismaterialismoreadvancedandcanbeskippedonyourfirstread-ing.“Joethedeveloper,”ourcartoonfriend,asksarelatedquestionthatyoumayfinduseful.PreparedexclusivelyforKimPartridgeChapter1IntroductionThisbooktellsyouhowtoimprovetheeffectivenessofyoursoftwaredevelopmentprocessusingversioncontrol.Versioncontrol,sometimescalledsourcecodecontrol,isthefirstlegofourprojectsupporttripod.Weviewtheuseofversioncontrolasmandatoryonallprojects.Versioncontroloffersmanyadvantagestobothteamsandindividuals:•Itgivestheteamaproject-wideundobutton;nothingisfinal,andmistakesareeasilyrolledback.Imagineyou’reusingtheworld’smostsophisticatedwordprocessor.Ithaseveryfunctionimaginable,exceptone.Forsomerea-son,theyforgottoaddsupportforaDELETEkey.Thinkhowcarefullyandslowlyyou’dhavetotype,particularlyasyougotneartheendofalargedocument.Onemis-take,andyou’dhavetostartagain.It’sthesamewithversioncontrol;havingtheabilitytogobackanhour,aday,oraweekfreesyourteamtoworkquickly,confidentthattheyhaveawayoffixingmistakes.•Itallowsmultipledeveloperstoworkonthesamecodebaseinacontrolledmanner.Theteamnolongerloseschangeswhensomeoneoverwritestheeditsmadebyanotherteammember.•Theversioncontrolsystemkeepsarecordofthechangesmadeovertime.Ifyoucomeacrosssome“surprisingcode,”it’seasytofindoutwhomadethechange,when,and(withanyluck)why.VERSIONCONTROLINACTION2•Aversioncontrolsystemallowsyoutosupportmultiplereleasesofyoursoftwareatthesametimeasyoucon-tinuewiththemainlineofdevelopment.Withaversioncontrolsystem,there’snolongeraneedfortheteamtostopworkduringacodefreezejustbeforerelease.•Versioncontrolisaproject-widetimemachine,allowingyoutodialinadateandseeexactlywhattheprojectlookedlikeonthatdate.Thisisusefulforresearch,butitisessentialforregeneratingpriorreleasesforcus-tomerswithproblems.Thisbookfocusesonversioncontrolfromaprojectperspec-tive.Ratherthansimplylistingthecommandsavailableinaversioncontrolsystem,weexplainthetasksyouneedtoper-formwellinasuccessfulprojectandthenshowhowaversioncontrolsystemcanhelp.Let’sstartwithasmallstory....1.1VersionControlinActionFredrollsintotheofficeeagertocontinueworkingonthenewOrinocobookorderingsystem.(WhyOrinoco?Fred’scom-panyusesthenamesofriversforallinternalprojects.)Aftergettinghisfirstcupofcoffee,Fredupdateshislocalcopyoftheproject’ssourcecodewiththelatestversionsfromthecen-tralversioncontrolsystem.Inthelogthatliststheupdatedfiles,henoticesthatWilmahaschangedcodeinthebasicOrdersclass.Fredgetsworriedthatthischangemightaffecthiswork,buttodayWilmaisoffattheclient’ssite,installingthelatestrelease,sohecan’taskherdirectly.Instead,Fredaskstheversioncontrolsystemtodisplaythenotesassoci-atedwiththechangetoOrders.Wilma’scommentdoeslittletoreassurehim:AddednewdeliveryPreferencesfieldtotheOrdersclassTofindoutwhat’sgoingon,hegoesbacktotheversioncon-trolsystemandaskstoseetheactualchangesmadetothesourcefile.HeseesthatWilmahasaddedacoupleofinstancevariables,buttheyaresettodefaultvalues,andnothingseemstochangethem.Thismightbeaprobleminthefuture,butitisnothingthatwillstophimtoday,soFredcontinuesworking.PreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION3Asheworksonhiscode,Fredaddsanewclassandacou-pleoftestclassestothesystem.Fredaddsthenamesofthefileshecreatestotheversioncontrolsystemashecreatesthem;thefilesthemselveswon’tbeaddeduntilhecommitshischanges,butaddingtheirnamesnowmeanshewon’tfor-gettoaddthemlater.Acoupleofhoursintotheday,Fredhascompletedthefirstpartofsomenewfunctionality.Itpassesitstests,anditwon’taffectanythingintherestofthesystem,sohedecidestocheckitallintotheversioncontrolsystem,makingitavailabletotherestoftheteam.Overtheyears,Fredhasfoundthatcheckingcodeinandoutfrequentlyworksbestforhim:it’saloteasiertoreconciletheoccasionalconflictifyouhavetoworryaboutonlyacoupleoffilesratherthanaweek’sworthofchangesfromthewholeteam.WhyYouShouldNeverAnswerthePhoneJustasFredisabouttostartthenextroundofcoding,hisphonerings.It’sWilma,callingfromtheclient’ssite.Itlookslikethere’sabuginthereleasesheisinstalling:printedinvoicesarenotcalculatingsalestaxonshippingamounts.Theclientisgoingballistic,andtheyneedafixnow....UnlessYouUseVersionControlFreddouble-checksthenameofthereleasewithWilmaandthentellstheversioncontrolsystemtocheckoutallthefilesinthatversionofthesoftware.HeputsitinatemporarydirectoryonhisPC,asheintendstodeleteitafterhefinishesthework.Henowhastwocopiesofthesystem’ssourcecodeonhiscomputer:thetrunk(themainlineofdevelopment)andtheversionreleasedtotheclient.Becauseheisabouttofixabug,hetellstheversioncontrolsystemtotaghissourcecodewithalabel.(He’lladdanothertagwhenhehasfixedthebug.Thesetagsactasflagsyouleavebehindtomarksignificantpointsinthedevelopment.Byusingconsistentlynamedtagsbeforeandafterhemakesthechange,otherfolksinhisteamwillbeabletoseeexactlywhatchangedshouldtheylookatitlater.)PreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION4Inordertoisolatetheproblem,Fredfirstwritesatest.Sureenough,itlookslikenooneevercheckedthesalestaxcal-culationwhenshippingwasinvolved,becausehistestimme-diatelyshowstheproblem.(Fredmakesanotetoraisethisduringthisiteration’sreviewmeeting;thisissomethingthatshouldneverhavegoneoutthedoor.)Sighing,Fredaddsthelineofcodethataddsshippingtothetaxabletotal,com-piles,andchecksthathistestpasses.Hererunsthewholetestsuiteasaquicksanitytestandchecksthefixedcodebackintothecentralversioncontrolsystem.Finally,hetagsthereleasebranchindicatingthatthebugisfixed.HesendsanoteofftoQA,whoisresponsibleforshippingemergencyreleasestotheclient.Usinghistag,they’llbeabletoinstructthebuildsystemtoproduceadeliverydiskthatincludeshisfix.FredthenphonesWilmaandtellsherthefixisinthehandsofQAandshouldbewithhersoon.Havingfinishedwiththislittledistraction,Fredremovesthesourceforthereleasedcodefromhislocalmachine:there’snopointinclutteringthingsup,andthechangeshehasmadearesafelytuckedbackintothecentralserver.Hethengetstowondering:isthesalestaxbughefoundinthereleasedcodealsopresentinthecurrentdevelopmentversion?Thequick-estwaytocheckistoaddthetesthewroteinthereleasedver-siontothedevelopmenttestsuite.Hetellstheversioncontrolsystemtomergethatparticularchangeinthereleasebranchintotheappropriatefileinthedevelopmentcopy.Themergeprocesstakeswhateverchangesweremadetothereleasefilesandmakesthesamechangestothedevelopmentver-sion.Whenherunsthetests,hisnewtestfails:thebugisindeedpresent.Hethenmoveshisfixfromthereleasebranchintothedevelopmentversion.(Hedoesn’tneedthereleasebranch’scodeonhismachinetodoanyofthis;allthechangesarebeingfetchedfromthecentralversioncontrolsystem.)Oncehehasthetestsallrunningagain,hecommitsthischangeintotheversioncontrolsystem.That’sonelessbugthat’llbitetheteamnexttime.Crisisover,Fredgetsbacktoworkingonhisowntasksfortheday.Hespendsahappyafternoonwritingtestsandcodeandtowardtheendofthedaydecidesheisdone.Whilehehasbeenworking,otherfolksinhisteamhavealsobeenmakingPreparedexclusivelyforKimPartridgeVERSIONCONTROLINACTION5changes,soheusestheversioncontrolsystemtotaketheirworkandapplyithislocalcopyofthesource.Herunsthetestsonelasttimeandthencheckshischangesbackin,readytostartworkthenextday.Tomorrow...Unfortunately,thenextdaybringsitsownsurprises.Over-nightFred’scentralheatingfinallygivesuptheghost.AsFredlivesinMinnesota,andasit’sFebruary,thisisn’tsomethingtobetakenlightly.Fredcallsintoworktosayhe’llbeoutmostofthedaywaitingfortherepairfolkstoarrive.However,thatdoesn’tmeanhehastostopworking.AccessinghisofficenetworkusingasecureconnectionoverthepublicInternet,Fredchecksoutthelatestdevelopmentcodeontohislaptop.Becausehecheckedinbeforehewenthomethepreviousnight,everythingisthereandup-to-date.Hecon-tinuestoworkathome,wrappedinablanketandsittingbythefire.Beforehestopsfortheday,hecheckshischangesinfromthelaptopsothey’llbeavailabletohimatworkthenextday.Lifeisgood(exceptfortheheatingrepairbill).
  • 相关资料
  • 该用户的其他资料
  • 名称/格式
  • 下载次数
  • 资料大小
  • 名称/格式
  • 下载次数
  • 资料大小

用户评论

0/200
暂无评论
上传我的资料

资料阅读排行

关闭

请选择举报的类型

关闭

提示

提交成功!

感谢您对爱问共享资料的支持,我们将尽快核实并处理您的举报信息。

关闭

提示

提交失败!

您的举报信息提交失败,请重试!

关闭

提示

重复举报!

亲爱的用户!感觉您对爱问共享资料的支持,请勿重复举报噢!

全屏 缩小 放大
收藏
资料评价:

/ 211
所需积分:0 立即下载
返回
顶部
举报
资料
关闭

温馨提示

感谢您对爱问共享资料的支持,精彩活动将尽快为您呈现,敬请期待!