I use Bazaar and I love it. Generally, I just create different branches and manage them separately. I've just found that all those branches can be put into a repository. If I understand correctly, this should save memory and increase speed as some common ancestor between branches are shared. Q1: Do I understand this right?
Another thing is that when I try to use it I found some problem which I really do not get it. Here is how I attempt.
bzr init-repo --trees TestBzrRepo
cd TestBzrRepo
bzr init trunk
mkdir branches
cd branches
bzr branch ../trunk b01-Add-file2-f
echo 'This is file 2' > file2.f
bzr add file2.f
bzr commit -m "Add file 2"
cd ../../trunk
echo 'This is file 1' > file1.f
bzr add file1.f
bzr commit -m "Add file 1"
cd ../branches/b01-Add-file2-f
From now if I do bzr pull ../../trunk
, I got:
bzr: ERROR: These branches have diverged. Use the missing command to see how.
Use the merge command to reconcile them.
If I do bzr merge ../../trunk
, I got:
bzr: ERROR: Branches have no common ancestor, and no merge base revision was specified.
bzr conflicts
returns nothing and I still cannot pull or merge.
What happen here? and What should I do next. Please help.
Thank you in advance.
I think the reason for the merge error is that you didn't create a revision before creating your second branch. bzr qlog TestBzrRepo
might help to make sense of the situation.
Try bzr merge ../../trunk -r 0..-1
.
bzr init-repo
creates a so-called shared repository. In a shared repository, all revisions are stored inside the .bzr
directory of the repository, and the .bzr
directories of the branches themselves store only branch meta information, not the the revisions themselves. This way the branch directories become very light-weight, and the common revisions of branches are not duplicated.
Let's say we created a shared repository and branches inside it like this:
bzr init-repo the-project # create shared repo
bzr init the-project/trunk # create a branch inside shared repo
cd the-project/trunk # cd to branch dir
cp -r /path/to/files/* . # copy the project's files into the branch
bzr add # tell bazaar to add everything to version control
bzr commit -m 'added files' # commit the changes (add files)
bzr branch . ../branch1 # create another branch from the current one
bzr branch . ../branch2 # create another branch from the current one
Then the directories of the layout will function like this:
the-project/.bzr -- only revisions are stored here, no branch info
the-project/trunk/.bzr -- only branch info is stored here, no revisions
the-project/branch1/.bzr -- only branch info is stored here, no revisions
the-project/branch2/.bzr -- only branch info is stored here, no revisions
If you were not using a shared repository the situation would be very different, for example:
bzr init trunk # create a repo
cd trunk # cd to repo dir
cp -r /path/to/files/* . # copy the project's files into the repo
bzr add # tell bazaar to add everything to version control
bzr commit -m 'added files' # commit the changes (add files)
bzr branch . ../branch1 # create another repo from the current one
bzr branch . ../branch2 # create another repo from the current one
In this case (no shared repo) the directories of the layout will function like this:
trunk/.bzr -- revisions + branch info are stored here
branch1/.bzr -- revisions + branch info are stored here
branch2/.bzr -- revisions + branch info are stored here
In this case the revisions will be duplicated in all 3 branches.
bzr pull
is useful if the current branch is some revisions behind the other branch, so that the missing revisions can be appended in a straightforward way. If the current branch has some revisions that the other doesn't, then the pull fails as in your example. This is perfectly normal, and the solution in such situation is to do a normal merge with bzr merge
.
bzr merge
fails in your example because the two branches (trunk and the other branch) have no common revisions. This is because at the time you branched from trunk, it was completely empty, no revisions were committed to it. The two branches are completely independent, have absolutely no common revisions.
It is still possible to combine unrelated branches as @bialix explained in a comment with bzr merge ../../trunk -r0..-1
but I don't think this was your intention. It is pointless to branch from a trunk that has no revisions, in a realistic use case you would branch from a branch that has at least 1 revisions, in which case you will not get such error and the merge will work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With