delete branch on mercurial with no commits - mercurial

I created a branch on a mercurial repo but I realized that I don't need it and so far there's no commits to it. It's never been pushed so I was wondering if I can delete from history permantly without having to rebase?

I don't think I can do it so I'll just clone the repo again.

New Solution:
Just use hg up default --clean. Works wonders.

Related

How do i undo the hg pull and update?

I am working in branch A and am using eclipse mercurial plugin to manage version control.Mistakely while pulling and updating the changes from the remote repository I pulled and updated changes of all the branches of my project.Now my branch A has changes of other branches say B , C , D .. as well.
I go-ogled and found out that hg rollback is likely the solution however I am not sure.
How do i undo my last pull and update? Any suggestion would be appreciated.
For a direct hands on How to revert a Mercurial hg pull?. Also look the Mercurial FAQ (7.13).
The hg update is never a problem, just do hg update YOUR_LOVED_REVISION_NUMBER and your working directory is again with all your stuff, and only your stuff.
Assuming you and only you works in the A branch, the hg pull is either a problem, just other's work in other's branches in your backstaged Mercurial internal history. If you like your history (DAG) clean then you may hg strip those annoying branches in your local repository.
Assuming the A branch is co-worked, then the hg pull just imported the other's work to your local copy of the project.

creating a new branch in mercurial: "abort: push creates new remote head"

I am trying to do something very simple: create a new branch. But I messed up. Where did I make the mistake, and how do I fix it?
I am the only user of Mercurial. I had revision 54 committed and pushed to remote repository. I wanted to create a branch based on revision 53, so I updated my local copy to revision 53, made changes, and committed (ignoring the warning about "it's not the head"). Then when I am trying to push to remote repository, it says
abort: push creates new remote head
Maybe I needed to tell Mercurial that I want to create a new branch? If so, how and at what point?
Thanks!
You tell Mercurial that it can go ahead with
$ hg push --force
You need to force it since multiple (unnamed) heads are normally discouraged. The problem with them is that people that clone the repository wont know which one to use. But since you're the only user you can just go ahead and push.
The alternative is to use a named branch (with hg branch) and then you'll use
$ hg push --new-branch
to allow the creation of a new branch on the remote. Named branches have the advantage that they make it easy to distinguish the two branches. They have the disadvantage that they are permanent. Permanent means that you cannot remove the branch name from the changesets on the branch — the name is literally baked directly into the changeset.
Bookmarks provide a way to have non-permanent branch names, see hg help bookmarks.
Another reason for this error: probably there are some UNMERGED changes form the central repo in your default branch.
hg up default
hg merge
hg ci -m "Merge"
hg pus
I did this. Using TortoiseHg ... this is how I fixed it:
In settings, I enabled the Strip extension then right clicked the branch i did not want, Modified History - strip. If you have pushed, then it needs to be stripped from all other repositories, including workmates who have pulled your unwanted branch.
An alternative is to merge the unwanted branch into your main branch, but do not take any of the changes from that branch - I am unsure of how that mechanism works.

Discard a local branch in Mercurial before it is pushed

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!
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.
I know its too late but it may be useful for any one:
If your branch is not pushed yet.
First rollback changes hg rollback only if you have done commit but
not yet pushed
Second run hg update --clean
Third run hg branch any-existing-branch
Fourth run hg pull -u
If you find yourself doing this often perhaps you should be using bookmarks instead of named branches. http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/

Undoing branch creation in Mercurial

How can I undo the creation of a branch in Mercurial? For example, if I issue the command
hg branch newbranch
How can I delete this branch if I decide I entered the wrong name? I'm guessing this must be pretty simple to do, but I have yet to figure it out. Thanks!
If you haven't committed yet, you can simply do a clean reset as per the manual (http://www.selenic.com/mercurial/hg.1.html#commands):
hg branch -C
This will reset the working directory's branch name to the parent of the branch that you just created.
if you haven't committed anything to it, it wasn't really created. so just issue another hg branch newname.
If its already commited:
hg clone -b branch1 [-b branch2 [-b ..]] oldrepo newrepo, i.e. every branch except newbranch, will result in new repo without the newbranch.
If mq extension is enabled then hg strip
Look into editing history before making permanent changes in repository.
Assuming you have not pushed to a remote repository, enable the mq extension and strip the branch off.

hg unbundle into new branch

Is it possible to unbundle bundled changesets into a new branch in a repository? I have tried switching to a new branch before performing the unbundle, but that doesn't work.
Basically I have started a new development line and realized my commits should have been in a new branch. I've done hg strip to remove the changesets into a bundle and now I would like to recommit this bundle to a new branch.
I suppose I could recreate patches for each commit and then recommit each manually (or perhaps write a script to do it), but this seems unnecessary. Thanks for the help!
In general, unbundle will add the old changesets exactly as they were (starting off from the same parent changeset). A nice alternative to recreating patches for each commit might be in using the transplant or rebase extension (I'd go for rebase in this case).
No. The branch attribute is part of the changeset itself and altering it would alter the hashid, essentially making it a different changeset. A bundle is just a push/pull done manually, and it can't alter the changesets so it can't change their branch. The only things that can are things that actually modify the changeset or recreate it like export/import, transplant, histedit, mq, and convert.
You could clone your repository to a temporary repository, unbundle the bundle into it, check the changes, and if you're satisfied, push them to your main repository. If you don't approve of the changes, simply delete the temporary repository and the bundle.