Create a new branch of the last two revisions of an existing branch?

Asked by Markus Korn

I 'accidentally' created some revisions in an existing branch, it now turns out that this revisions are worth a completely new branch in a different project. How can I create a new branch out of the last revisions of an existing branch, with forgetting all other changes?

Let's have a look at an example:
*let's say I have the following branch structure:

mkdir base
cd base
bzr init
echo 1 > 1
bzr add
bzr commit -m "rev 1"
echo 2 > 2
bzr add
bzr commit -m "rev 2"
echo 3 > 3
bzr add
bzr commit -m "rev 3"
echo 4 > 4
bzr add
bzr commit -m "rev 4"

* now it turns out that revision 3 and 4 are unrelated to this branch, how can I create a new branch having the old revision #3 as revision #1 and the old revision #4 as revision #2?

the result should look like the result of:

bzr diff -r -3.. > ../diff.diff
mkdir ../new
cd ../new
bzr init
bzr patch ../diff.diff
bzr add
bzr commit -m "rev 3 and 4"

plus the revision history

My first idea was to try something like
bzr branch base -r -3.. , but bzr branch is not working for ranges of revisions

luks showed me how to use bzr replay on #bzr, but this way I did not get the expected result (maybe I did not do it the right way)

Is it even possible with bzr?

Thanks for your help,
Markus

Question information

Language:
English Edit question
Status:
Solved
For:
Bazaar Edit question
Assignee:
No assignee Edit question
Solved by:
Marius Kruger
Solved:
Last query:
Last reply:
Revision history for this message
Marius Kruger (amanica) said :
#1

2008/12/3 Markus Korn <email address hidden>

> New question #53349 on Bazaar:
> https://answers.edge.launchpad.net/bzr/+question/53349
>
> I 'accidentally' created some revisions in an existing branch, it now turns
> out that this revisions are worth a completely new branch in a different
> project. How can I create a new branch out of the last revisions of an
> existing branch, with forgetting all other changes?
>
> Let's have a look at an example:
> *let's say I have the following branch structure:
>
> mkdir base
> cd base
> bzr init
> echo 1 > 1
> bzr add
> bzr commit -m "rev 1"
> echo 2 > 2
> bzr add
> bzr commit -m "rev 2"
> echo 3 > 3
> bzr add
> bzr commit -m "rev 3"
> echo 4 > 4
> bzr add
> bzr commit -m "rev 4"
>
> * now it turns out that revision 3 and 4 are unrelated to this branch, how
> can I create a new branch having the old revision #3 as revision #1 and the
> old revision #4 as revision #2?
>

the following worked for me:

cd..
bzr branch base -r 2 base2
cd base2
bzr merge -r 3..4 ../base/
bzr commit -m "rev 4"

(optionally, to remove rev 4, but be carefull if you have uncomitted
changes)
cd ../base
bzr uncomit
bzr revert

note that obviously the 2 rev4's will be considered different revisions,
but that wont cause conflicts since its the same change.

Revision history for this message
Markus Korn (thekorn) said :
#2

Thanks Marius for your anwser. But this does not solve my problem. This way I'm loosing the revision history of all merged revisions, for example I don't see all the commit messages for revisions 3 and 4.

Revision history for this message
Marius Kruger (amanica) said :
#3

2008/12/4 Markus Korn <email address hidden>

> Markus Korn is still having a problem:
> Thanks Marius for your anwser. But this does not solve my problem. This
> way I'm loosing the revision history of all merged revisions, for
> example I don't see all the commit messages for revisions 3 and 4.
>

I think you might be able to use the rebase plugin to replay the revisions
after rev3
http://people.samba.org/bzr/jelmer/bzr-rebase/trunk

Revision history for this message
Markus Korn (thekorn) said :
#4

My problem is: I don't understand how this rebase plugin works, should I use "bzr rebase" or "bzr replay", other plugins and bzr itself have wonderful workflow examples, unfortunately the rebase plugin is missing this kind of documentation.

Marius, can you please give me an example on how to use this rebase plugin?

I tried to use it in ways like this, but it fails with messages like "Nothing to rebase" or, when slightly modified, "bzr: ERROR: Reserved revision-id {null:}":

cd /tmp
mkdir base
cd base
bzr init
echo 1 > 1
bzr add
bzr commit -m "rev 1"
echo 2 > 2
bzr add
bzr commit -m "rev 2"
echo 3 > 3
bzr add
bzr commit -m "rev 3"
echo 4 > 4
bzr add
bzr commit -m "rev 4"
cd ..
bzr branch base -r 0 last_rev
cd last_rev
bzr rebase ../last_rev

Thanks in advance

Revision history for this message
Best Marius Kruger (amanica) said :
#5

Sorry I misread your initial question.

One way is to undo rev 1..2 :
bzr merge -r2..0 .
bzr commit -m "undo first couple of revs"

Anyways i tried replay and got it working:
(make /tmp/base)
bzr init ../base2
cd ../base2

$ bzr replay ../base -r 3..4
bzr: ERROR: Reserved revision-id {null:}

which is what you also got. So i tried to just do a initial commit:

bzr commit -m "initial commit" --unchanged
Committing to: /tmp/base2/
Committed revision 1.

then it worked like a dream

$ bzr replay ../base -r 3..4
All changes applied successfully.
Committing to: /tmp/base0/
added 3
Committed revision 2.
All changes applied successfully.
Committing to: /tmp/base0/
added 4
Committed revision 3.

I assume its a bug that you can't replay onto a branch with no revisions.

Revision history for this message
Markus Korn (thekorn) said :
#6

Thanks a lot Marius, this initial commit did the trick,
you are my hero of the day ;)

Revision history for this message
Markus Korn (thekorn) said :
#7

Thanks Marius Kruger, that solved my question.

Revision history for this message
Marius Kruger (amanica) said :
#8