1

I want a Mercurial analogue of git reset HEAD~2 (completely abandon the last 2 commits -- but keep the local file changes).

In my specific case, I wanted to abandon all changes since the last hg pull, so what I did was:

hg clone $(hg paths default) tmp
rm -rf .hg
mv tmp/.hg .
rm -rf tmp

Is there an "official" way to do this?

The answers to Mercurial — revert back to old version and continue from there keep the bad commits. I want to abandon them - but not the local changes.

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278

1 Answers1

3

To delete revisions from the repository, keeping the files:

hg strip --keep firstBadRevisionToDelete
Marcos Zolnowski
  • 2,751
  • 1
  • 24
  • 29
  • `keep ... delete` looks suspicious. – sds Feb 09 '17 at 04:50
  • 2
    @sds: it may *look* suspicious, but it's correct: `--keep` means "do not modify working directory during strip" and takes no argument. Meanwhile `hg strip` takes one argument, which is the specific changeset to remove (which in turn removes all its descendants). You can make it look less suspicious by adding `-r`, i.e., `hg strip -k -r `. Side note: You might also consider committing the current work-tree and then using `hg histedit` to flatten everything down. – torek Feb 09 '17 at 07:55