开发者

Should I use push or switch to create branch in bazaar?

To create a branch in bazaar, I can do two things:

  • Checkout the trunck, do modifications, local commit and then push my version to MyProject/MyBranch

or

    开发者_如何转开发
  • create MyProject/MyBranch and switch my checkout to the new branch, then do modification and commit.

My questions:

  • Does this two operations produce the same result ?
  • What is the best pratices about branch ?


I wasn't sure what would happen when a checkout with local commits was pushed, so I tried it out.

It turns out that in both cases, you'll end up with history like:

trunk:

  1. old commit
  2. etc.

branch:

  1. new commit
  2. old commit
  3. etc.

However, branching first and working with a checkout of the branch is a much better way to do it. If you have a checkout with local commits and do a bzr update you won't be able to bzr push before committing.

Secondly, if you have a checkout of the trunk with local commits, 'bzr push' to create the branch, then try to 'bzr switch` to the branch, you first have to commit or revert to avoid the "Cannot switch as local commits found in the checkout" error.


Edit: this answer assumes a different setup than the question describes, as the initial formulation of the question was unclear.

The two operations you've described to not create the same result. Whether the differences will be meaningful or not depends a lot on your environment. For example, whether you're working with other developers or on your own.

In the first case, you've got a branch with a working tree. When you push to a location that is not already a branch, you create a new branch with the same history as the initial branch.

In your second example, it seems you are working with an existing checkout. I'm not sure what you mean about creation of a branch folder.

Whether you decide to work with branches with working trees or with checkouts really depends on what you want to do. If you have a bunch of features of the same project which you want to keep isolated from one another, it seems to make sense to work with a checkout. In this case, the working tree is only stored once on disk, and the branches just keep track of the modifications for each feature. At some point, you will probably want to merge one or more of these branches together to combine those features back into a single branch.

On the other hand, if you have two distinct projects, it might make sense to have two branches, each with their own working tree.

Reading the Bazaar Workflows document, bzr help checkouts and bzr help branches may help you decide which approach will work best for your situation.


To answer your first question, I don't believe it will produce the same result.

Your first option will produce this history:

trunk:

  1. new commit
  2. old commit
  3. etc.

branch:

  1. new commit
  2. old commit
  3. etc.

i.e. The trunk and the branch will have identical history.

Your second option will produce this history:

trunk:

  1. old commit
  2. etc.

branch:

  1. new commit
  2. old commit
  3. etc.

i.e. Your new commit will only appear on the branch. To get it on the trunk with this method, you would have to merge the branch into the trunk.

The best practice would be depend on what you want to accomplish. If you're making a branch to commit some changes that you don't want on trunk yet, then branch first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜