Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discard a local branch in Mercurial before it is pushed

Tags:

Many times it happens that I have few commits on my local Hg repository which I don't want to push and sometimes I want to remove the local branch altogether. But I cannot rollback more than one commit which leaves me no choice than creating a new clone and download the whole repository again. This feels stupid, since if I could just delete my local branch which has not affected the remote repository in anyway, then I wouldn't have to create and setup a new clone. So, is it how it is in Mercurial or is there some way to discard a local branch?

Thanks!

like image 605
orad Avatar asked Aug 08 '11 22:08

orad


People also ask

How do I delete a branch in Mercurial?

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. In mercurial - it is a set of changesets.

How do I change my branch on mercurial?

Quickly switch to another branch or bookmarkIn the Status bar, click the Mercurial Branch widget to open the Branches popup. Select the branch or bookmark to which you want to switch and in the menu that opens, click Update.

What is mercurial default branch?

Mercurial's main branch is called "default" and is analogous to "trunk" in SVN, "HEAD" in CVS, and "master" in Git. If you try to use some other name for your "main" branch, users will get a more or less random branch when they clone and commit things in the wrong place, which is generally undesirable.


1 Answers

If you enable the mq extension (bundled with Mercurial), you can use hg strip. Be careful, though, as this will modify the history of your repository. The safe method is to clone your repository up to the revision preceding the creation of the branch you want to discard, then to pull the remaining changesets that you want to keep.

like image 82
Remy Blank Avatar answered Oct 05 '22 04:10

Remy Blank