BazaarNG Tutorial.docx
《BazaarNG Tutorial.docx》由会员分享,可在线阅读,更多相关《BazaarNG Tutorial.docx(12页珍藏版)》请在冰豆网上搜索。
BazaarNGTutorial
Bazaar-NGTutorial
Currentforbzr-0.8,2006-04
Introduction
Ifyouarealreadyfamiliarwithdecentralizedrevisioncontrol,thenpleasefeelfreetoskipaheadto"IntroducingYourselftoBazaar-NG".If,ontheotherhand,youarefamiliarwithrevisioncontrolbutnotdecentralizedrevisioncontrol,thenpleasestartat"HowDRCSisdifferent."Otherwise,getsomecoffeeortea,getcomfortableandgetreadytocatchup.
ThePurposesofRevisionControl
Oddsarethatyouhaveworkedonsomesortoftextualdata--thesourcestoaprogram,websitesortheconfigfilesthatUnixsystemadministratorshavetodealwithin/etc.Thechancesarealsogoodthatyouhavemadesomesortofmistakethatyoudeeplyregretted.Perhapsyoudeletedtheconfigurationfileforyourmailserverorperhapsmauledthesourcecodeforapetproject.Whateverhappened,youhavejustdeletedimportantinformationthatyouwoulddesperatelyliketogetback.Ifthishaseverhappenedtoyou,thenyouareprobablyreadyforBazaar-NG.
Revisioncontrolsystems(whichI'llhenceforthcallRCS)suchasBazaar-NGgiveyoutheabilitytotrackchangesforadirectorybyturningitintosomethingslightlymorecomplicatedthanadirectorythatwecallabranch.Thebranchnotonlystoreshowthedirectorylooksrightnow,butalsohowitlookedatvariouspointsinthepast.Then,whenyoudosomethingyouwishyouhadn't,youcanrestorethedirectorytothewayitlookedatsomepointinthepast.
Revisioncontrolsystemsgiveuserstheabilitytosavechangestoabranchby"committingarevision".Therevisioncreatedisessentiallyasummaryofthechangesthatweremadesincethelasttimethetreewassaved.
Theserevisionshaveotherusesaswell.Forexample,onecancommentrevisionstorecordwhattherecentsetofchangesmeantbyprovidinganoptionallogmessage.Reallifelogmessagesincludethingslike"Fixedthewebtemplatetoclosethetable"and"Addedsftpsuppport.Fixes#595"
Wekeeptheselogssothatiflaterthereissomesortofproblemwithsftp,wecanfigureoutwhentheproblemprobablyhappened.
HowDRCSisDifferent
ManyRevisionControlSystems(RCS)arestoredonservers.IfonewantstoworkonthecodestoredwithinanRCS,thenoneneedstoconnecttotheserverand"checkout"thecode.Doingsogivesoneadirectoryinwhichapersoncanmakechangesandthencommit.TheRCSclientthenconnectstotheRCSserverandstoresthechanges.Thismethodisknownasthecentralizedmodel.
Thecentralizedmodelcanhavesomedrawbacks.AcentralizedRCSrequiresthatoneisabletoconnecttotheserverwheneveronewantstodoversioncontrolwork.Thiscanbeabitofaproblemifyourserveronsomeothermachineontheinternetandyouarenot.Or,worseyet,you''are''ontheinternetbuttheserverismissing!
DecentralizedRevisionControlSystems(whichI'llcallDRCSafterthispoint)dealwiththisproblembykeepingbranchesonthesamemachineastheclient.InBazaar-NG'scase,thebranchiskeptinthesameplaceasthecodethatisbeingversioncontrolled.Thisallowstheusertosavehischanges(commit)wheneverhewants--evenifheisoffline.Theuseronlyneedsinternetaccesswhenhewantstoaccessthechangesinsomeoneelse'sbranchthataresomewhereelse.
Acommonrequirementthatmanypeoplehaveistheneedtokeeptrackofthechangesforadirectorysuchasfileandsubdirectorychanges.Performingthistrackingbyhandisaawkwardprocessthatovertimebecomesunwieldy.Thatis,untiloneconsidersversioncontroltoolssuchasBazaar-NG.Thesetoolsautomatetheprocessofstoringdatabycreatingarevisionofthedirectorytreewhenevertheuserasks.
RevisioncontrolsoftwaresuchasBazaar-NGcandomuchmorethanjuststorageandperformingundo.Forexample,withBazaar-NGdevelopercantakethemodificationsinonebranchofsoftwareandapplythemtoanother,related,branch--evenifthosechangesexistinabranchownedbysomebodyelse.Thisallowsdeveloperstocooperatewithoutgivingwriteaccesstorepository.
Bazaar-NGremembersthe''ancestry''ofarevision:
thepreviousrevisionsthatitisbasedupon.Asinglerevisionmayhavemorethanonedirectdescendant,eachwithdifferentchanges,representingadivergenceintheevolutionofthetree.Bybranching,Bazaar-NGallowsmultiplepeopletocooperateontheevolutionofaproject,withoutallneedingtoworkinstrictlock-step.Branchingcanbeusefulevenforasingledeveloper.
IntroducingyourselftoBazaar-NG
Bazaar-NGinstallsasinglenewcommand,bzr.Everythingelseisasubcommandofthis.Youcangetsomehelpwithbzrhelp.Therewillbemoreinthefuture.
Onefunctionofaversioncontrolsystemistokeeptrackofwhochangedwhat.Inadecentralizedsystem,thatrequiresanidentifierforeachauthorthatisgloballyunique.Mostpeoplealreadyhaveoneofthese:
anemailaddress.Bzrissmartenoughtoautomaticallygenerateanemailaddressbylookingupyourusernameandhostname.Ifyoudon'tliketheguessthatBazaar-NGmakes,thenthreeoptionsexist:
1.Setanemailaddressviabzrwhoami.Thisisthesimplestway.Tosetaglobalidentity,use:
%bzrwhoami'YourName'
Ifyou'dliketouseadifferentaddressforaspecificbranch,enterthebranchfolderanduse:
%bzrwhoami--branch'YourName'
1.Settingtheemailaddressinthe~/.bazaar/bazaar.conf[1]byaddingthefollowinglines.Pleasenotethat[DEFAULT]iscasesensitive:
[DEFAULT]
email=YourName
Asabove,youcanoverridethissettingsonabranchbybranchbasisbycreatingabranchsectionin~/.bazaar/locations.confandaddingthefollowinglines:
[/the/directory/to/the/branch]
email=YourName
1.Overridingthetwopreviousoptionsbysettingtheglobalenvironmentvariable$BZREMAILor$EMAIL($BZREMAILwilltakeprecedence)toyourfullemailaddress.
[1]
(1,2)OnWindows,theusersconfigurationfilescanbefoundintheapplicationdatadirectory.Soinsteadof~/.bazaar/branch.conftheconfigurationfilecanbefoundas:
C:
\DocumentsandSettings\\ApplicationData\Bazaar\2.0\branch.conf.Thesameistrueforlocations.conf,ignore,andthepluginsdirectory.
Creatingabranch
Historyisbydefaultstoredinthe.bzrdirectoryofthebranch.Therewillbeafacilitytostoreitinaseparaterepository,whichmayberemote.Wecreateanewbranchbyrunningbzrinitinanexistingdirectory:
%mkdirtutorial
%cdtutorial
%ls-a
./../
%pwd
/home/mbp/work/bzr.test/tutorial
%
%bzrinit
%ls-aF
./../.bzr/
%
AsforCVS,therearethreeclassesoffile:
unknown,ignored,andversioned.Theaddcommandmakesafileversioned:
thatis,changestoitwillberecordedbythesystem:
%echo'helloworld'>hello.txt
%bzrstatus
unknown:
hello.txt
%bzrunknowns
hello.txt
%bzraddhello.txt
addedhello.txt
%bzrunknowns
Ifyouaddthewrongfile,simplyusebzrremovetomakeitunversionedagain.Thisdoesnotdeletetheworkingcopy.
Branchlocations
Allhistoryisstoredinabranch,whichisjustanon-diskdirectorycontainingcontrolfiles.Bydefaultthereisnoseparaterepositoryordatabaseasusedinsvnorsvk.Youcanchoosetocreatearepositoryifyouwantto(seethebzrinit-repocommand).Youmaywishtodothisifyouhaveverylargebranches,ormanybranchesofamoderatesizedproject.
You'llusuallyrefertobranchesonyourcomputer'sfilesystemjustbygivingthenameofthedirectorycontainingthebranch.bzralsosupportsaccessingbranchesoverhttp,forexample:
%bzrloghttp:
//bazaar-ng.org/bzr/bzr.dev/
Byinstallingbzrpluginsyoucanalsoaccessbranchesoverthesftporrsyncprotocols.
Reviewingchanges
Onceyouhavecompletedsomework,youwillwanttocommitittotheversionhistory.Itisgoodtocommitfairlyoften:
wheneveryougetanewfeatureworking,fixabug,orimprovesomecodeordocumentation.It'salsoagoodpracticetomakesurethatthecodecompilesandpassesitstestsuitebeforecommitting,tomakesurethateveryrevisionisaknown-goodstate.Youcanalsoreviewyourchanges,tomakesureyou'recommittingwhatyouintendto,andasachancetorethinkyourworkbeforeyoupermanentlyrecordit.
Twobzrcommandsareparticularlyusefulhere:
statusanddiff.
bzrstatus
Thestatuscommandtellsyouwhatchangeshavebeenmadetotheworkingdirectorysincethelastrevision:
%bzrstatus
modified:
foo
Bydefaultbzrstatushides"boring"filesthatareeitherunchangedorignored.Toseethemtoo,usethe--alloption.Thestatuscommandcanoptionallybegiventhenameofsomefilesordirectoriestocheck.
bzrdiff
Thediffcommandshowsthefulltextofchangestoallfilesasastandardunifieddiff.Thiscanbepipedthroughmanyprogramssuchas''patch'',''diffstat'',''filterdiff''and''colordiff'':
%bzrdiff
***addedfile'hello.txt'
---/dev/null
+++hello.txt
@@-1,0+1,1@@
+helloworld
Withthe''-r''option,thetreeiscomparedtoanearlierrevision,orthedifferencesbetweentwoversionsareshown:
%bzrdiff-r1000..#everythingsincer1000
%bzrdiff-r1000..1100#changesfrom1000to1100
The--diff-optionsoptioncausesbzrtoruntheexternaldiffprogram,passingoptions.Forexample:
%bzrdiff--diff-options--side-by-sidefoo
Someprojectspreferpatchestoshowaprefixatthestartofthepathforoldandnewfiles.The--prefixoptioncanbeusedtoprovidesuchaprefix.Asashortcut,bzrdiff-p1producesaformthatworkswiththecommandpatch-p1.
Committingchanges
Whentheworkingtreestateissatisfactory,itcanbecommittedtothebranch,creatinganewrevisionholdingasnapshotofthatstat