开发者

How can I prune branches with cloning in Mercurial?

Let's say I have a mercurial project and I do this:

hg branch whatever
touch newfile
hg add newfile
hg commit -m "added newfile" --close-branch
hg up -C default
hg merge whatever
hg 开发者_如何学Pythonpush
abort: push creates new remote branch 'whatever'!
(did you forget to merge? use push -f to force)

How can I remove the branch so that hg branches -c will not show it there? It's kind of frustrating that this is not allowing me to push to bitbucket. I read the Documentation, but the first two points I'm probably not following correctly ( since I keep getting the error, even though I merged ). The third point, about removing via clone I don't understand how to do, since I always end up with the feature branch in my repo too.


If whatever was a good, legitimate branch (say, a feature branch), and you want it to be in the Bitbucket repo, you should do hg push --new-branch. Without this switch, Mercurial thinks, hey, maybe you didn't want to push this branch at all, maybe it's private and you're about to make a mistake.

If you don't want whatever to be a real named branch, you can use bookmarks instead of named branches. Unlike named branches, bookmarks can later be removed.

Edit: If what you want to achieve is to make the history linear after you have completed the development in the branch, what you want to do is rebase. There are two cases:

No new changesets in the Bitbucket repo. In this case, you just delete the bookmark and push, because there are no heads to merge/rebase. Remember, with bookmarks, AD are in branch default.

1 -- 2 -- 3 -- A -- B -- C -- D
               ^              ^
               your work      'whatever' bookmark

New changesets in the Bitbucket repo. You pull, then rebase your work on top of the Bitbucket repo tip, then delete the bookmark and push.

               new changeset you pulled
               v
1 -- 2 -- 3 -- 4 -- 5 
            \
              A -- B -- C -- D
              ^              ^
              your work      'whatever' bookmark

You do hg rebase -B whatever to make the history linear:

               new changeset you pulled
               v
1 -- 2 -- 3 -- 4 -- 5 -- A -- B -- C -- D
                         ^              ^
                         your work      'whatever' bookmark

And then delete the bookmark, and push.

Rebasing creates new changesets, so be sure to never rebase changesets you have already pushed.


Well, first of all, you don't have to remove that branch.

The warning is just that, a warning that you should double-check that you're indeed doing the right thing, and not pushing a branch somewhere it doesn't belong.

However, if you want to keep the branch, just do what the warning says, push with the -f option:

hg push -f

Now, on the other hand, if you do want to remove it, here's the ways you can do it:

Strip

If you have the "mq" extension enabled, you can strip off the changeset:

 hg strip REV

This removes the revision REV, and everything that follows from it, from the repository.

You should only do this in a clone if you're unsure about the effect or whether you really want this

MQ

Another way is to pop the changesets you don't want to push into a queue. I don't know if this will work with a whole branch, neither do I know the exact command for this.

Clone

Basically you clone what you want to keep

hg clone --branch default original newclone

This will clone from original to newclone and only clone the default branch. If you want to clone more than the default branch, you can repeat the --branch NAME option for each branch you want to clone.

Again, make sure you experiment with fresh clones and verify that you get what you want before pushing anything to the central repository.


You can commit with the --close-branch switch to close the branch so it doesn't show when you do hg branches. Anyway you will have to push with --new-branch since you just created one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜