noob - understanding branches diverged
Neil Martinsen-Burrell
nmb at wartburg.edu
Wed Apr 15 03:26:57 BST 2009
Mike Mattie <codermattie <at> gmail.com> writes:
> I am new to bzr, and very pleased with it. I have run into a persistent
> issue that I don't quite understand though.
Welcome! Many of us here started the same way.
> When I am pushing from my laptop to a shared repository on my main
> development machine, and then I pull on my main development machine I keep
> getting "this branch has diverged".
>
> shared repo
> / \
> / \
> laptop home box
>
> 1. laptop: branch from shared repo
> 2. home box: branch from shared repo
> 3. laptop: hack hack hack
> 4. laptop: push to shared-repo
>
> 5. home box: pull - "branches have diverged"
> 6. home box: merge .... works.
>
> The problem with the merge is that I get a big fat lump of changes I end up
> having to commit as a single transaction.
Pull is a command to make the current branch an exact mirror of another
branch. So, when you tell your home box to ``bzr pull`` from the shared repo,
it is trying to make the branch on our home box into an exact copy of the one
in the shared repo (which should be the same as the one you pushed from your
laptop). If you have revisions in your home branch that are not in your
laptop branch, then the branches have "diverged" and you can't just add on the
new revisions from your laptop, instead you have to merge them. Merging just
means using your human intervention to ensure that the combination of
revisions from your laptop and your home branch is reasonable.
The large group of changes that you commit as a single transaction is *not* a
single lump though. Bazaar preserves all of the history from your laptop in
your home branch after you merge. Bazaar recently changed to not show you
those revisions by default, but if you specify ``bzr log --levels=0`` then you
will be able to see all of the revisions that led up to your merge.
> What I usually do is cherry pick the changes into feature branches, so a big
> commit does not work, and I always do the merging on the home box, although
> I could do it on the laptop too ... but the laptop is slow. 300mhz, just
> enough to run Emacs.
>
> Can someone point me to a url, document etc, that explains branch
> diversion ? or enlighten me a bit ?
An enlightening thing for me is to try to replicate what I'm seeing in a very
simple setting. The easy branching in Bazaar makes this almost fun::
nmb at guttle[~]$ cd /tmp
nmb at guttle[/tmp]$ bzr init laptop
Created a standalone tree (format: pack-0.92)
nmb at guttle[/tmp]$ bzr init shared
Created a standalone tree (format: pack-0.92)
nmb at guttle[/tmp]$ bzr init home
Created a standalone tree (format: pack-0.92)
nmb at guttle[/tmp]$ cd laptop
nmb at guttle[/tmp/laptop]$ echo "new file" > a
nmb at guttle[/tmp/laptop]$ bzr add
adding a
nmb at guttle[/tmp/laptop]$ bzr ci -m 'project starts here'
Committing to: /private/tmp/laptop/
added a
Committed revision 1.
nmb at guttle[/tmp/laptop]$ bzr push ../shared
All changes applied successfully.
Pushed up to revision 1.
nmb at guttle[/tmp/laptop]$ cd ../home
nmb at guttle[/tmp/home]$ bzr pull ../shared
+N a
All changes applied successfully.
Now on revision 1.
Now all of my branches have the same content. I'm going to make a change at
home, then more changes on my laptop, push the laptop to the shared branch
and try to pull it from home::
nmb at guttle[/tmp/home]$ echo "home at last" >> a
nmb at guttle[/tmp/home]$ bzr ci -m 'doing my homework'
Committing to: /private/tmp/home/
modified a
Committed revision 2.
nmb at guttle[/tmp/home]$ cd ../laptop
nmb at guttle[/tmp/laptop]$ echo "on the go" > b
nmb at guttle[/tmp/laptop]$ bzr add
adding b
nmb at guttle[/tmp/laptop]$ bzr ci -m 'working remotely'
Committing to: /private/tmp/laptop/
added b
Committed revision 2.
nmb at guttle[/tmp/laptop]$ echo "this won't conflict with my home branch" > c
nmb at guttle[/tmp/laptop]$ bzr add
adding c
nmb at guttle[/tmp/laptop]$ bzr ci -m 'more files'
Committing to: /private/tmp/laptop/
added c
Committed revision 3.
nmb at guttle[/tmp/laptop]$ bzr push
Using saved push location: /private/tmp/shared/
All changes applied successfully.
Pushed up to revision 3.
nmb at guttle[/tmp/laptop]$ cd ../home
nmb at guttle[/tmp/home]$ bzr pull
Using saved parent location: /private/tmp/shared/
bzr: ERROR: These branches have diverged. Use the merge command to
reconcile them.
As you have seen, this is what results. So, let's do what the error suggests
and merge::
nmb at guttle[/tmp/home]$ bzr merge
Merging from remembered parent location /private/tmp/shared/
+N b
+N c
All changes applied successfully.
nmb at guttle[/tmp/home]$ bzr st
added:
b
c
pending merge tips: (use -v to see all merge revisions)
Neil Martinsen-Bu... 2009-04-14 more files
nmb at guttle[/tmp/home]$ bzr st -v
added:
b
c
pending merges:
Neil Martinsen-Bu... 2009-04-14 more files
Neil Martinsen-Bu... 2009-04-14 working remotely
nmb at guttle[/tmp/home]$ bzr ci -m 'include the latest laptop stuff'
Committing to: /private/tmp/home/
added b
added c
Committed revision 3.
nmb at guttle[/tmp/home]$ bzr log --levels=0
3 Neil Martinsen-Burrell 2009-04-14 [merge]
include the latest laptop stuff
1.1.2 Neil Martinsen-Burrell 2009-04-14
more files
1.1.1 Neil Martinsen-Burrell 2009-04-14
working remotely
2 Neil Martinsen-Burrell 2009-04-14
doing my homework
1 Neil Martinsen-Burrell 2009-04-14
project starts here
The [merge] in revision 3 indicates that revision included some new revisions
from elsewhere. Using --levels, you can see exactly what those revisions
were. I'm not sure how cherry-picking from feature branches makes this
undesirable, but I this is what I usually want.
> I will zap the laptop working-copy and re-branch it, but I want to avoid
> this in the future.
I don't think there's any reason to zap anything on your laptop. A ``bzr pull
--overwrite`` will accomplish the same thing: make your laptop an exact
replica of your shared branch.
-Neil
More information about the bazaar
mailing list