R – Merge two checkouts in bazaar

bazaarcheckoutmerge

I'm just starting out with bazaar, and I've found that the checkout feature is the most useful for the way I work – namely I can c/o from a "master copy", do some development and then commit my changes in the new directory. This then updates the "master copy".

But what if I'm working on (eg) two projects, changing different portions of code? Say:

~/master                - master copy
bzr co master ./gui
bzr co master ./engine

So I'm doing gui-related stuff in the ./gui directory and under-the-hood stuff in ./engine. How should I commit my changes? If I commit gui first, then engine, I guess any conflicts will be flagged in engine?

Is there a way to merge gui and engine, and then do just one commit to the master copy?

To make things a little more complicated, how about if I do this:

bzr branch gui ./mouse

Now I perhaps I've been working on mouse, but also on gui. If I want to merge the code from gui AND mouse, and then commit to master, what is the best way to manage this? Or indeed, if I also:

bzr branch gui ./keyboard

If I've changed altered gui, keyboard and mouse, should I hierarchically merge – ie mouse+keyboard, then merge this with gui, then commit gui to master?

I hope it is clear what I'm trying to achieve! Thanks in advance for your time.

Best Answer

If you have two checkouts, any time you commit changes to one, you will first have to pull down any changes from the other one, potentially having to resolve conflicts at each step. This is generally a good idea, since it's easier to resolve conflicts over time and make sure your code doesn't diverge too much.

However, it sounds like you want to have separate developers working on "gui" and "engine", or you just want to save your conflict resolution till development on both branches has completed. In this case, you should probably create them as independent branches with "bzr branch". Each branch can use local commits and not worry about conflicts with each other. Then when it comes time to merge you can do it one of 3 ways, all of which get the same end result:

1. Merge one branch into the other, then push it up to master:

cd gui
bzr merge ../engine
# manually fix any conflicts
bzr commit
bzr push #back up to main

The downside to the above method is that your "gui" branch now has the "engine" changes in it. Which is fine if you're going to throw away both branches once they're pushed back into the mainline. But if you want to keep the branches longer, you can:

2. Merge into the mainline:

cd master
bzr merge ../gui
bzr commit
bzr merge ../engine
# manually fix conflicts
bzr commit

This has the upside that you still have "gui" and "engine" as separate branches, but you've had to commit one to master before you were sure that they would both work together. So you really probably want to:

3. Create a merge branch:

bzr branch ~/master gui-engine-merge
cd gui-engine-merge
bzr merge ../gui
bzr commit
bzr merge ../engine
# manually fix conflicts
bzr commit
bzr push ~/master
# since this branch was only for merging, you don't need it anymore:
cd ..
rm -r gui-engine-merge