Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a mercurial repo with no uncommitted changes. I was on revision 846, and decided my last 2 commits were junk and wanted to carry on as if from revision 844. So I was going to type:

hg revert -r 844 --all

Unfortunately I mistyped, and wrote:

hg revert -r 44 --all

So my whole repository has changed dramatically, including directory structure. I don't see any .orig files, so I don't think the answer in:

How to undo a revert in mercurial

helps me.

hg log still has all of my commits up to revision 846 - do you think I can revert back to revision 846?

Advice very welcome

share|improve this question

1 Answer

up vote 1 down vote accepted

hg revert just sets your working copy to the revision that you specify so if you didn't do a commit after the revert then your repository has not changed. To fix it you can just do hg update -C and then delete all the .orig files.

After that you can do the correct revert statement to remove the last two revisions.

If you did do the commit then the command that you wanted to do (hg revert -r 844 --all) would still get you to the point that you want by undoing the revert commit as well as the two commits that you originally intended to undo.

share|improve this answer
Thanks very much! I didn't commit, I noticed the problem as soon as I hit <return>, thankfully. Can I ask, why the "-C" in update? I'm digging around the mercurial manual/book/website and can't find a clear statement of what it is for. If I did "hg update", that would take me to the current head, which is revision 846, which is what I want. I can find references to -C being used for named branches, which seems irrelevant? – user1213546 20 hours ago
I used hg update tip - worked perfectly. Thanks again – user1213546 20 hours ago
hg update -C discards uncommitted changes and I wouldn't have thought that it would have worked without it. It certainly didn't work in my tests. – Steve Kaye 19 hours ago
I didn't have any uncommitted changes - maybe that's why? When I say it worked - I ended up with a working directory that matched my expectations. I also had a bunch of .orig files, and (more confusingly) I had a whole load of old files in their old locations without .orig. So I had to do some cleaning up. Is that consistent with your expectations and tests? – user1213546 18 hours ago
Yes, it seemed like it didn't really work and you cleaned it up manually. :) You should have had uncommitted changes because you changed your working copy to be the same as revision 44 and those changes were uncommitted. – Steve Kaye 17 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.