I have broken some code in my last 4-5 revisions / pushes to main repository. At now I want to completely delete this pushes and start HEAD of my repository from that point. How can I do that? In SVN there is dump command, which copies whole repository from one revision to another. There is some substitute in Mercurial or some other way?
2 Answers
You can use the convert extension to do that.
Although, I don't really understand why people always want to hide/remove in their VCS history that they made a mistake. It's not that critical as long as you fix it in a newer revision...

- 11,819
- 6
- 44
- 61
-
gizmo, I agree completely about deleting history being a bad idea. – Ry4an Brase Sep 24 '10 at 15:57
-
It is not a bad idea when you have sensitive information that needs to be completely erased, without losing the history of a project. A common mistake is finding out too late that a sensitive password was checked into a project that needs to be published to a wider audience. The conversation about best practices is irrelevant, being able to fix it is what is important. Hg is a power tool. It shouldn't try to think for me. The fact is, sensitive information _will_ come out. The question is what do we lose to accomplish it. Forcing the user to use the nuclear option isn't the best way. – codenheim Feb 24 '16 at 11:26
Quardas, "completely deleting" isn't part of mercurial's default vocabulary. It's a system built around immutable history. You can reverse something you regret, but you don't delete it. Think of a scientist in his/her lab writing with pen on numbered pages in a logbook -- ripping out a page is considered fraud. There's value in having your blind-allys and mistakes retained if only so you remember not to try that again.
Consider using hg backout
which easily and automatically adds the inverse of a changeset thus undoing it completely, but preserving the record of both the changeset and the reversal of it.
If you really can't buy into that concept try looking into clone -r
. It lets you clone your repository up to a certain point. For example:
hg clone -r -6 myrepo partial-myrepo
mv myrepo myrepo-with-stuff-I-regret
mv partial-myrepo myrepo
that will replace your repo with a new copy that omits the last five changesets.
Ther are plenty of other ways to do the same thing using tools that aren't part of mercurial's default toolset (extensions such as histedit, strip, mercurial queues, etc.) but you're best off not deleting history at all and doing it w/o extensions if you do.

- 78,112
- 7
- 148
- 169
-
Not when the scientist owns the lab and the logbook and writes down a password he should have kept elsewhere, or in his head. When a developer makes a mistake of information disclosure, keeping the mistake is not best. Some mistakes aren't code errors, some are passwords and private keys and proprietary documents that have to be erased/extracted before publishing. With SVN, it was as simple as svnadmin dump, global replace, restore new repos from dump. It should be that easy with hg because its a common accident. – codenheim Feb 24 '16 at 11:40
-
Sure, but this question was about broken code. Histedit and friends make actual modification of history easier than a dump and a restore, but of course with any system there's the caveat that anything others have already gotten at is gone. Usually better to just create new credentials. – Ry4an Brase Feb 24 '16 at 17:08