Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete Mercurial branch after merge

Tags:

I am creating named Mercurial branches for new features in my application, and after I finish a particular feature, I merge that branch into default branch, and close this feature branch.

But I wonder if there is way to remove those named branches completely, without losing changes that are merged into default branch?

like image 466
Ivica Avatar asked Aug 31 '12 10:08

Ivica


People also ask

Can I delete a branch after merge?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

How do I delete my mercurial branch?

You cannot. You can close the branch to hide it from the list of active branches, but you cannot completely delete it. This happens because in mercurial and in git the "branch" term means different things.

What happens if I delete a merged branch?

If you DELETE the branch after merging it, just be aware that all hyperlinks, URLs, and references of your DELETED branch will be BROKEN.

Can I delete branch before merge?

The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.


1 Answers

No there isn't.

When you have merged the two branches, the merge commit depends on the existence of its two parent commits. That means that you can't remove the commits making up the merged branch, unless you also delete the merge commit, which you don't want to do.

This is also not the "Mercurial way" to do things. When a branch has been merged into another branch, and no further development has been done on that branch, Mercurial recognizes that that branch is not active anymore; hg branches will put those inactive branches at the bottom of the list. You can also close a branch by using hg commit --close-branch, which will remove the branch from the hg branches list (unless the -c parameter is given).

It sounds like you should look into Mercurial queues (MQ), because this supports a similar workflow to what you describe. E.g., you can set up multiple MQ queues, and each of these represents a branch of development.

like image 91
daniel kullmann Avatar answered Oct 02 '22 18:10

daniel kullmann