I'm using Mercurial with TortoiseHG Workbench. I closed a branch by accident. I tried updating to it and making a commit to see if it would reopen (since there didn't appear to be an option to reopen the branch)
I was able to make a commit and push, but on TortoiseHG, it still says that the Head is Closed!
Option to reopen branch doesn't exist, because commit on top of closed head effectively open this head (and commited head must not be "closed": it's metadata from previous changeset): test this with hg branches and|or hg heads
Additional reading:
Is it possible to reopen a closed branch in Mercurial?
New changesets on a closed branch that must make it to default
I found out what happened.
On TortoiseHG, I clicked the Branch: button to close a branch. When I updated to my correct branch, I noticed that I forgot to check that the button does not say "close current branch".
A simple commit should solve this problem
Related
I have created three branches by mistake.
I closed them by command hg commit --close-branch -m "Closing this head".
Then I switched to another branch MVDM-9.
I want to push my changes to a remote repository, but I get this error.
hg push
pushing to ssh://hg#bitbucket.org/Predictix/mvideo-modeler
searching for changes
abort: push creates new remote branches: MVDM-57C, MVDM-57T, MVDM-60!
(use 'hg push --new-branch' to create new remote branches)
MVDM-57C, MVDM-57T, MVDM-60 are the branches which I closed.
How do I resolve the problem?
You have a couple of options here.
First option (safe)
You can just push the revisions you want to push rather than pushing everything. You just use
hg push -r <revision_number>
substituting <revision_number> with the latest revision number that you want to push, and it will then only push that revision and the revisions that went into it.
Second option (dangerous)
If you have never pushed, pulled or copied the branches that you closed to anywhere else and you don't want to keep them for the history and will never use them then you can strip the changes.
Make sure you take a backup clone of your repository before you start doing this because you could easily destroy your existing copy.
You will need to enabled the strip extension first if it's not already enabled, and then the usage is
hg strip -r <revision_number>
This will delete <revision_number> and all its children from the repository, so you need to be careful what revision you select to delete.
If you've got TortoiseHg installed you can do this via the Workbench UI and you can do it a revision at a time until you've got what you want.
You can always use option 1 first, and then after you've pushed the revisions you want up to the remote repo you can strip the unwanted branches from your local copy.
This question already has answers here:
Is there any way to delete local commits in Mercurial?
(10 answers)
Closed 8 years ago.
I have situation like this:
I have commited files a,b,c,d.Now i found that by mistake i commited
files a and b; so before pushing these changes, i want to do uncommit
files a and b so that i can push only c and d.Can someone tell me how
to do that by using mercurial commands.
Here uncommit means that i dunt want to use "hg out -p" and after that
looking change set and do things manually.
Assuming you haven't performed any other transactions on your repository since you committed the files, I think you could do this as a 2 stage process:
hg rollback
hg commit filec filed
hg rollback should remove the commit that you have just made, but leave the files as changed. Then hg commit filec filed should commit the files named filec & filed. Obviously you should replace these file names with the names of your actual files.
It's probably worth mentioning that you should be careful with hg rollback - it alters the history, so it is possible to lose data with it if used incorrectly.
hg rollback, and you can find more in the Chapter 9. Finding and fixing mistakes of the Mercurial: The Definitive Guide
In mercurial you can use the backout command, which creates a changeset that is the opposite of the changeset you want to backed out. Then this changeset is committed. The only thing you need to do after that is a merge.
You can backout any changeset, but it's not recommended to backout a merge changeset.
A detailed explanation of the command with an example can be found here.
for some reason "hg ci --close-branch" is coming up as an command not found in my mercurial. how do I get around this to close the branch in a different way?
thanks!
Your mercurial is too old. Close branch was added in version 1.6 or 1.7. You should upgrade, which is quite easy on most any platform.
Failing that there's no way to close a branch, but you can make it inactive by merging it into another branch. Both closed and inactive non-final for a named branch -- they never really go away.
I understand that it is possible to close a named branch in Mercurial, so that it will not appear in the hg branches list:
hg commit --close-branch -m 'close badbranch, this approach never worked'
Is it possible to later re-open the branch if need be?
You can just hg update to the closed branch then do another hg commit and it will automatically reopen.
The closed flag is just used to filter out closed branches from hg branches and hg heads unless you use the --closed option - it doesn't prevent you from using the branches.
You can reopen a branch by using the "-f" flag when 'creating' the branch.
No, this command will create a new branch with the same name.
Just forget that it's closed. Switch to the branch, make the changes and commit. It will be automatically reopened. When you're done you can close it again.
try with following:
hg pull && hg update branch_name
Now make a small change to one of the file and then commit it
hg commit -m "minor change"
then push it
hg push -b .
Now you should be able to work normally.
Try this.
Switch to the closed branch before executing. ( hg up closed_branch )
hg st
touch a
add a
hg commit -m 'reopening the closed branch'
This will reopen the closed branch.
I've got a named branch (same repository) that was created in order to to spike something. I've now decided that I want to move all the changesets created in the branch back into the main (default) and then close the branch.
I've tried a number of different things, including what was outlined in this post (How to repeatedly merge branches in Mercurial) but I just can't get it working :(
Can anyone provide any pointers?
Thanks.
Merge the feature branch into default
hg up default
hg merge feature-branch-name
hg ci -m 'merged feature-branch-name into default'
Close the branch you don't want to use anymore
hg up feature-branch-name
hg ci --close-branch -m 'close feature-branch-name branch'
hg up default
Note that the close command doesn't have any disruptive effects on the repository history
It flags your branch as closed so that it won't appear in hg branches and hg heads commands output
I've managed to solve my problem using the link I mentioned in my question. The steps described in the link had actually merged my changes across however I didn't realise as I was looking in the TortoiseHg UI and couldn't see the changes there. When I performed hg outgoing via the command line it appears that the merge had worked correctly.