Reputation: 314
I have my own branch in a project where there are 2 development branches (let's call them "the new one" and "the old one". I merged with "the new one", then by mistake I merged with "the old one" and now my branch is a total mess.
Is there any way for me to get my branch to look exactly like "the new one" without creating a new branch? I don't care about loosing my changes, its only a few lines and I can do it again.
Upvotes: 1
Views: 399
Reputation: 489045
Rather than wipe out everything, why not wipe out exactly the one bad merge?
Mercurial allows you to remove a revision, provided you also remove all commits that are descendants of that revision. This is an extension, but it's bundled with all modern versions of Mercurial (since 2.8), so you merely need to enable it by adding strip =
to your [extensions]
section of your configuration.
Merging (and then committing the merge) creates a revision. You say (I think) that you first ran hg merge <correct thing>
and committed, then ran hg merge <incorrect thing>
and committed.
In this case, the most recent revision is the incorrect one that you would like to strip out. This would remove any revisions that descend from the merge as well, but if the last thing you did was hg merge <incorrect thing> && hg commit
, there are no such revisions anyway.
So, find out what the wrong revision number is—run hg log
to view the last few revisions, for instance—and then run hg strip -r <wrongrev>
. That will remove that revision (and all its descendants).
See also https://www.mercurial-scm.org/wiki/StripExtension and this answer to Mercurial — revert back to old version and continue from there.
Upvotes: 1