1、BazaarNG TutorialBazaar-NG TutorialCurrent for bzr-0.8, 2006-04IntroductionIf you are already familiar with decentralized revision control, then please feel free to skip ahead to Introducing Yourself to Bazaar-NG. If, on the other hand, you are familiar with revision control but not decentralized re
2、vision control, then please start at How DRCS is different. Otherwise, get some coffee or tea, get comfortable and get ready to catch up.The Purposes of Revision ControlOdds are that you have worked on some sort of textual data - the sources to a program, web sites or the config files that Unix syst
3、em administrators have to deal with in /etc. The chances are also good that you have made some sort of mistake that you deeply regretted. Perhaps you deleted the configuration file for your mailserver or perhaps mauled the source code for a pet project. Whatever happened, you have just deleted impor
4、tant information that you would desperately like to get back. If this has ever happened to you, then you are probably ready for Bazaar-NG.Revision control systems (which Ill henceforth call RCS) such as Bazaar-NG give you the ability to track changes for a directory by turning it into something slig
5、htly more complicated than a directory that we call a branch. The branch not only stores how the directory looks right now, but also how it looked at various points in the past. Then, when you do something you wish you hadnt, you can restore the directory to the way it looked at some point in the pa
6、st.Revision control systems give users the ability to save changes to a branch by committing a revision. The revision created is essentially a summary of the changes that were made since the last time the tree was saved.These revisions have other uses as well. For example, one can comment revisions
7、to record what the recent set of changes meant by providing an optional log message. Real life log messages include things like Fixed the web template to close the table and Added sftp suppport. Fixes #595We keep these logs so that if later there is some sort of problem with sftp, we can figure out
8、when the problem probably happened.How DRCS is DifferentMany Revision Control Systems (RCS) are stored on servers. If one wants to work on the code stored within an RCS, then one needs to connect to the server and checkout the code. Doing so gives one a directory in which a person can make changes a
9、nd then commit. The RCS client then connects to the RCS server and stores the changes. This method is known as the centralized model.The centralized model can have some drawbacks. A centralized RCS requires that one is able to connect to the server whenever one wants to do version control work. This
10、 can be a bit of a problem if your server on some other machine on the internet and you are not. Or, worse yet, you are on the internet but the server is missing!Decentralized Revision Control Systems (which Ill call DRCS after this point) deal with this problem by keeping branches on the same machi
11、ne as the client. In Bazaar-NGs case, the branch is kept in the same place as the code that is being version controlled. This allows the user to save his changes (commit) whenever he wants - even if he is offline. The user only needs internet access when he wants to access the changes in someone els
12、es branch that are somewhere else.A common requirement that many people have is the need to keep track of the changes for a directory such as file and subdirectory changes. Performing this tracking by hand is a awkward process that over time becomes unwieldy. That is, until one considers version con
13、trol tools such as Bazaar-NG. These tools automate the process of storing data by creating a revision of the directory tree whenever the user asks.Revision control software such as Bazaar-NG can do much more than just storage and performing undo. For example, with Bazaar-NG developer can take the mo
14、difications in one branch of software and apply them to another, related, branch - even if those changes exist in a branch owned by somebody else. This allows developers to cooperate without giving write access to repository.Bazaar-NG remembers the ancestry of a revision: the previous revisions that
15、 it is based upon. A single revision may have more than one direct descendant, each with different changes, representing a divergence in the evolution of the tree. By branching, Bazaar-NG allows multiple people to cooperate on the evolution of a project, without all needing to work in strict lock-st
16、ep. Branching can be useful even for a single developer.Introducing yourself to Bazaar-NGBazaar-NG installs a single new command, bzr. Everything else is a subcommand of this. You can get some help with bzr help. There will be more in the future.One function of a version control system is to keep tr
17、ack of who changed what. In a decentralized system, that requires an identifier for each author that is globally unique. Most people already have one of these: an email address. Bzr is smart enough to automatically generate an email address by looking up your username and hostname. If you dont like
18、the guess that Bazaar-NG makes, then three options exist:1. Set an email address via bzr whoami. This is the simplest way. To set a global identity, use:% bzr whoami Your Name If youd like to use a different address for a specific branch, enter the branch folder and use:% bzr whoami -branch Your Nam
19、e 1. Setting the email address in the /.bazaar/bazaar.conf 1 by adding the following lines. Please note that DEFAULT is case sensitive:DEFAULTemail= Your Name As above, you can override this settings on a branch by branch basis by creating a branch section in /.bazaar/locations.conf and adding the f
20、ollowing lines:/the/directory/to/the/branchemail=Your Name 1. Overriding the two previous options by setting the global environment variable $BZREMAIL or $EMAIL ($BZREMAIL will take precedence) to your full email address.1(1, 2) On Windows, the users configuration files can be found in the applicati
21、on data directory. So instead of /.bazaar/branch.conf the configuration file can be found as: C:Documents and SettingsApplication DataBazaar2.0branch.conf. The same is true for locations.conf, ignore, and the plugins directory.Creating a branchHistory is by default stored in the .bzr directory of th
22、e branch. There will be a facility to store it in a separate repository, which may be remote. We create a new branch by running bzr init in an existing directory:% mkdir tutorial% cd tutorial% ls -a./ ./% pwd/home/mbp/work/bzr.test/tutorial% bzr init% ls -aF./ ./ .bzr/%As for CVS, there are three cl
23、asses of file: unknown, ignored, and versioned. The add command makes a file versioned: that is, changes to it will be recorded by the system:% echo hello world hello.txt% bzr statusunknown: hello.txt% bzr unknownshello.txt% bzr add hello.txtadded hello.txt% bzr unknownsIf you add the wrong file, si
24、mply use bzr remove to make it unversioned again. This does not delete the working copy.Branch locationsAll history is stored in a branch, which is just an on-disk directory containing control files. By default there is no separate repository or database as used in svn or svk. You can choose to crea
25、te a repository if you want to (see the bzr init-repo command). You may wish to do this if you have very large branches, or many branches of a moderate sized project.Youll usually refer to branches on your computers filesystem just by giving the name of the directory containing the branch. bzr also
26、supports accessing branches over http, for example:% bzr log http:/bazaar-ng.org/bzr/bzr.dev/By installing bzr plugins you can also access branches over the sftp or rsync protocols.Reviewing changesOnce you have completed some work, you will want to commit it to the version history. It is good to co
27、mmit fairly often: whenever you get a new feature working, fix a bug, or improve some code or documentation. Its also a good practice to make sure that the code compiles and passes its test suite before committing, to make sure that every revision is a known-good state. You can also review your chan
28、ges, to make sure youre committing what you intend to, and as a chance to rethink your work before you permanently record it.Two bzr commands are particularly useful here: status and diff.bzr statusThe status command tells you what changes have been made to the working directory since the last revis
29、ion:% bzr statusmodified: fooBy default bzr status hides boring files that are either unchanged or ignored. To see them too, use the -all option. The status command can optionally be given the name of some files or directories to check.bzr diffThe diff command shows the full text of changes to all f
30、iles as a standard unified diff. This can be piped through many programs such as patch, diffstat, filterdiff and colordiff:% bzr diff* added file hello.txt- /dev/null+ hello.txt -1,0 +1,1 +hello worldWith the -r option, the tree is compared to an earlier revision, or the differences between two vers
31、ions are shown:% bzr diff -r 1000. # everything since r1000% bzr diff -r 1000.1100 # changes from 1000 to 1100The -diff-options option causes bzr to run the external diff program, passing options. For example:% bzr diff -diff-options -side-by-side fooSome projects prefer patches to show a prefix at
32、the start of the path for old and new files. The -prefix option can be used to provide such a prefix. As a shortcut, bzr diff -p1 produces a form that works with the command patch -p1.Committing changesWhen the working tree state is satisfactory, it can be committed to the branch, creating a new revision holding a snapshot of that stat
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1