[wiki]bzr初学者的经历
发表于 : 2006-05-19 1:38
This story covers the individual hacker named Barry. Barry likes to work independantly on free software projects. He's got a small pile of small free software projects. Barry hasn't been using revision control on his projects because he felt that doing so wouldn't be worth the effort.
Unfortunately for poor Barry, one of his ten users has complained about a bug that has been in his code for the last couple features. This bug wasn't complicated, but was spread throughout the code in lots of little pieces that made it difficult for Barry to track down. Barry, realizing that he doesn't want to repeat this type of effort again, decides to move to using a revision control system.
Barry wanted to get his code controlled as easily as possible. He wanted all of the bells and whistles of a RCS system, but didn't want to pay the cost of setting up RCS servers. Thusly, he chose Bazaar-NG. Barry decided to start controlling a project that he forked years ago, something called Tuxpuck.
The first thing that Barry did was to get a copy of his own sources, which he put into a directory named tuxpuck (if you are following along with bzr yourself, feel free to import something you've got, perhaps by running cp -a /etc/init.d ~/tuxpuck). He then performed the following actions:
Barry was pretty happy with this. He decided to give bzr a few more commits so that he could get a feel for how commits went:
Barry, like much of us, leads a hectic life. He wanders off for a few days and comes back, unable to remember what he did. To get around this, he runs "bzr log:"
This pleases Barry quite a bit, mostly because Barry hasn't worked with a revision control system a bit (Note: This is my imaginary friend and I can make him easy to please if I want!)
However, this doesn't please Barry for too long; he wants more than just to be able to to save changes. What he'd really like to do is to work on two things at the same time, so that he get a feel for branching:
What he's just done now is tell bazaar-ng to make a copy of his old tuxpuck branch and make a new one in the newpuck directory. These two branches are absolutely identical, except for location. In a moment of inspiration, Barry realizes this means that he could have made a copy of his branch in other ways... He could have run "cp -a tuxpuck newpuck", he could have rsynced the branch to another machine, or even done a copy by transcribing by hand, if he had been so inclined.
This is cool and all, but what's the point of having a two branches that are exactly the same? Thusly, Barry makes some changes to newpuck:
Barry, like many people, gets distracted for a few days and walks off. When he comes back he can't remember how tuxpuck and newpuck are different. To figure out how the two trees are different, he runs:
*
Note: The branch: revision specifier is available on 0.7 and later versions. If Barry were using 0.6 or earlier, he'd need to do something like:
Barry decides that he likes the changes that he did to the newpuck branch the other day and decides to merge it into his main tuxpuck branch. Thusly, he ran the following:
Sure enough, bzr merged the changes that he made in the newpuck branch into the tuxpuck branch. He wonders, though, what happens with slightly more complicated files. Barry decides to try a slightly more complicated test:
Now he's ready to try something a little different: He's going to try and make the a different change to the same file in two different branches:
Barry is now comfortable knowing that my_brag is different in two different places. But can bzr merge them?
So far so good! So Barry commits and tries it the other way:
"This seems pretty cool!" Barry says to himself. He takes a quick look at the my_brag in newpuck, and sure enough, both typos have been fixed.
But what would happen if Barry had tried to merge two branches that had changes in the same place? This results in something called a conflict. A conflicted file is a bit of a headache to deal with that is a bit difficult to explain at this point. We'll get to that later.
This wraps up the first chapter of the Bzr chronicles. In this chapter you learned, by actually performing, the following things:
* How to import a new project into bazaar-ng
* How to branch in bazaar-ng
* How to check the differences between two branches in bazaar-ng
* How to merge between two branches in bazaar-ng
Unfortunately for poor Barry, one of his ten users has complained about a bug that has been in his code for the last couple features. This bug wasn't complicated, but was spread throughout the code in lots of little pieces that made it difficult for Barry to track down. Barry, realizing that he doesn't want to repeat this type of effort again, decides to move to using a revision control system.
Barry wanted to get his code controlled as easily as possible. He wanted all of the bells and whistles of a RCS system, but didn't want to pay the cost of setting up RCS servers. Thusly, he chose Bazaar-NG. Barry decided to start controlling a project that he forked years ago, something called Tuxpuck.
The first thing that Barry did was to get a copy of his own sources, which he put into a directory named tuxpuck (if you are following along with bzr yourself, feel free to import something you've got, perhaps by running cp -a /etc/init.d ~/tuxpuck). He then performed the following actions:
代码: 全选
~$ cd tuxpuck
~/tuxpuck$ bzr init
~/tuxpuck$ echo "I have become truely omnimematic" > my_brag
~/tuxpuck$ bzr add my_brag
added my_brag
~/tuxpuck$ bzr commit -m"Started up"
代码: 全选
~/tuxpuck$ echo "Don't brag. I guess I'm not omnimematic" > my_brag
~/tuxpuck$ bzr commit -m"Bragging is bad"
modified my_brag
代码: 全选
~/tuxpuck$ bzr log
------------------------------------------------------------
revno: 2
committer: James Blackwell <jblack@merconline.com>
timestamp: Wed 2005-09-07 01:09:14 -0400
message:
Bragging is bad
------------------------------------------------------------
revno: 1
committer: James Blackwell <jblack@merconline.com>
timestamp: Wed 2005-09-07 01:08:42 -0400
message:
Started up
However, this doesn't please Barry for too long; he wants more than just to be able to to save changes. What he'd really like to do is to work on two things at the same time, so that he get a feel for branching:
代码: 全选
~/tuxpuck$ cd
~$ bzr branch tuxpuck newpuck
This is cool and all, but what's the point of having a two branches that are exactly the same? Thusly, Barry makes some changes to newpuck:
代码: 全选
~$ cd newpuck
~/newpuck$ echo "Don't brag. I guess I don't remember all" > my_brag
~/newpuck$ bzr commit -m"Variation in humility"
modified my_brag
代码: 全选
~/tuxpuck$ bzr diff -r branch:../newpuck
[a lot of output from diff]
Note: The branch: revision specifier is available on 0.7 and later versions. If Barry were using 0.6 or earlier, he'd need to do something like:
代码: 全选
~/tuxpuck$ cd
~$ diff -ruN -x .bzr tuxpuck newpuck
[a lot of output from diff]
Barry decides that he likes the changes that he did to the newpuck branch the other day and decides to merge it into his main tuxpuck branch. Thusly, he ran the following:
代码: 全选
~$ cd tuxpuck
~/tuxpuck$ bzr merge ../newpuck/
0 conflicts encountered.
~/tuxpuck$ cat my_brag
Don't brag. I guess I don't remember all
代码: 全选
~/tuxpuck$ cat << EOF > my_brag
> This stuff seems to
> be working pretty good so farr.
>
> I wonder if it will kepe working
> EOF
~/tuxpuck$ bzr commit -m"Making a longer example"
modified my_brag
~/tuxpuck$ cd ../newpuck
~/newpuck$ bzr merge ../tuxpuck
0 conflicts encountered.
~/newpuck$ bzr commit -m"Catching newpuck up with tuxpuck"
modified my_brag
代码: 全选
~/newpuck$ sed -i s/kepe/keep/ my_brag
~/newpuck$ bzr commit -m "I fixed the mispelled keep"
modified my_brag
~/newpuck$ cd ../tuxpuck
~/tuxpuck$ sed -i s/farr/far/ my_brag
~/tuxpuck$ bzr commit -m "I fixed the mispelled farr"
代码: 全选
~/tuxpuck$ bzr merge ../newpuck/
0 conflicts encountered.
~/tuxpuck$ cat my_brag
This stuff seems to
be working pretty good so far.
I wonder if it will keep working
~/tuxpuck$
代码: 全选
~/tuxpuck$ bzr commit -m"Merged in from newpuck"
modified my_brag
~/tuxpuck$ cd ../newpuck
~/newpuck$ bzr merge ../tuxpuck/
0 conflicts encountered.
代码: 全选
~/newpuck$ bzr commit -m"Saving the merge from tuxpuck"
modified my_brag
This wraps up the first chapter of the Bzr chronicles. In this chapter you learned, by actually performing, the following things:
* How to import a new project into bazaar-ng
* How to branch in bazaar-ng
* How to check the differences between two branches in bazaar-ng
* How to merge between two branches in bazaar-ng