views:

395

answers:

3

(I am a relative newcomer to TortoiseHg, so bear with me :-) I use TortoiseHg on two machines to talk to my remote source repository. I made changes on one machine, committed them, and attempted to push them to the remote repository BUT I forgot to first do a pull to get the latest code first. The push gave me a few lines of output, suggesting I may have forgotten to pull first (true!) and mentioned something like "abort: push creates new remote branches...".

So I did a pull, which added several nodes to the head of my graph in the repository explorer. The problem is that the push I tried to do is now showing as a branch in the repository explorer. Looking from the server side (codeplex), it shows no sign of my attempted push, indicating this accidental branch is still local on my machine.

How could I remove this accidental branch? I tried selecting that node in the graph then doing "revert" but it did not seem to do anything. I am wondering if it would be simplest to just discard my directory tree on my local machine and do a completely new, clean pull from the server...?

+3  A: 

First make sure you have committed all your local changes. Then merge the branches by calling hg merge and commit the result.

This should bring you back to a single branch, reuniting the two heads.

sth
That sounds like the branch will still be there, yes? I am hoping to completely remove the branch, since I have not yet made it permanent on the server.
msorens
@msorens: The two changesets that were committed "in parallel" will remain that way, but does it matter? With the merge, the two branches will be joined together in a single top revision. From then on there will again be only a single newest revision, even though it has a short fork into two branches in its predecessors.
sth
@msorens: I agree with sth. After a while using Mercurial, you realize that trying to keep your revision history squeaky-clean just isn't worth the trouble. It doesn't matter that the changesets are out of sequence between your server and your local repos or that you've got a short-lived anonymous branch (both of which are to be expected if you have more than one person working on a project).
Niall C.
I agree with what you are saying but, yes, I think it does matter--in this case. Again I am new to TortoiseHg so correct me if I am wrong: Right now, this branch is only on my local repository. Why pollute the permanent record (on the server) with this superfluous branch? It just adds "noise" for no reason. So if there is no command within Mercurial to prune the branch it still seems to me that I should just discard my local directory and do a fresh pull. Is there any disadvantage to doing this?
msorens
@msorens: the only disadvantage is that it's more work for you, including having to manually merge the changes into the fresh local repo.
Niall C.
@msorens: I agree with the guys, just leave it. :) I'm sure, however, that a lot of folks will chime in with other answers suggesting you use 'hg strip' or 'hg clone -r' or histedit or mercurial queues. Any of those will do, but when you see what a hassle they are you'll invariably say, "I can't believe there isn't an easier way to do this," and everyone will chime in with "that's because it isn't supposed to be easy." That's the usual pattern any way, and we all went through it.Philosophically mercurial is about an indelible record of work, sort of like scientists always writing in pen.
Ry4an
Points noted; thanks to all for your feedback, and I will be more careful with my "pen" ! :-)
msorens
+1  A: 

In the Repository explorer, choose the first rev of your local changes, then right click on the tip of the branch you just pulled and choose "Rebase on top of selected." This will "re-base" your revs on the pulled ones.

Additionally, to help avoid it in the future...

In Repository Explorer, choose Tools->Settings. In the top left drop-down, choose "User global settings", so this applies to all repositories. Then choose Synchronize on the left. In "After Pull Operation" choose "rebase". This will cause your local revisions to be "rebased" upon the revisions you just pulled, rather than leaving them in a different branch.

This is how I do it and is probably what you typically want.

For more info, see the rebase project and the rebase extension.

Kyle Heironimus
[I am splitting this in 2 comments due to SO restrictions.] I like the notion of this. Just a couple things: First, no such option on my context menu. The RebaseExtension page provided the answer--enable it by putting a couple lines in the configuration file, which can be found by referring to section 5 of the Mercurial manual. I did that and than ran a rebase: it complained about unsupported file types for two files ending in .orig which were created by the rebase operation itself! It then indicated it aborted so I could fix the conflicts, and said to run "hg rebase --continue" when done...
msorens
[Part 2 of my split comment] But since I am running in TortoiseHg not the cmd line, not sure how I would do the "rebase -- continue" operation... Lastly, the confirmation says, in my case, "rebase 14 on top of 6?". That seems backward to me: 14 is the pulled main branch; 6 is my local branch.
msorens
@msorens re: Context Menu - It's kind of awkward. You must first choose one rev by left clicking, causing it to be highlighted. Then choose the next by right-clicking, which should then show both revs highlighted and give you the rebase option. If it's not showing up for you, sounds like maybe another question.
Kyle Heironimus
@msorens re: backwards - I told you the wrong order. I have now corrected by answer. Sorry.I'm not sure what to do about continue. For this one time, you can run the Windows command line. I believe TortoiseHg installs this as well. (If not, you should install it anyway. It comes in handy sometimes.)
Kyle Heironimus
kyle: you misunderstood my comment on the context menu not appearing--I tried to explain that it was a problem but that I fixed it by enabling it in the configuration file.
msorens
A: 

Do a "Merge With" and check "Discard all changes from merge target (other) revision". Of course you should make sure that the target shown as the merge target is really the one you want to throw away before you click the Merge button.

mhenry1384