noob - understanding branches diverged
Mike Mattie
codermattie at gmail.com
Thu Apr 16 20:51:46 BST 2009
On Wed, Apr 15, 2009 at 02:26:57AM +0000, Neil Martinsen-Burrell wrote:
> 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.
First of all thank you for the excellent reply, and the effort to explain it so
clearly. I was able to understand the issue with your help.
I think I should add a bit more context ... I am using a cherry picking tool
that I wrote myself.
http://www.emacswiki.org/emacs-en/Submerge
Submerge is a elisp based Emacs interface for cherry picking with
merge tracking.
It loads a bzr log into a buffer, finds the boundries of the commits,
and then builds a interface on top of the log buffer.
When you type "p" or "n" it jumps to the previous or next unmerged change.
"m" merges a commit.
Merging is done with the "bzr merge -c" command.
Successful merges are colored in green, errors in red ... etc.
It tracks previous merges by writing a commit message it can extract later..
submerge revid <number>.
I have posted the code as a very early release. There are still known issues.
In short it is currently suitable only for feedback by elisp hackers. I am
hoping to finish it up by April though, where it would be generally usable.
I will do some testing on my own, but maybe what I need to do is modify my
log scanner to handle log --levels=0, assuming that I can cherry pick those
sub-commits, from your example the 1.1.1 commits.
If it is ok within mailing list etiquette I would like to post an announcement
to this list when submerge is ready for some beta testing and contribution
by other elisp programmers.
Thank you again for the detailed reply, and the excellent work by the
bzr developers to create this wonderful tool.
>
> > 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
>
>
>
>
--
GnuPG Key: B9012279 is available from HKP server pgp.mit.edu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090416/e114092d/attachment.pgp
More information about the bazaar
mailing list