2

How do you abandon all repository changes since the last commit in Mercurial?

I don't think that this is the revert command, because that will actually update the working directory to the last commit. I just want to undo changes in the repository (added files, removed files, etc).

But, I'm new with Mercurial, so I could be missing something.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
  • *added files, removed files* are not changes to repository. Until commit there is no changes to repository whatsoever. – SilentGhost May 05 '10 at 12:38
  • 1
    Does this answer your question? [Mercurial — revert back to old version and continue from there](https://stackoverflow.com/questions/2540454/mercurial-revert-back-to-old-version-and-continue-from-there) – Mark Rotteveel Jul 30 '22 at 06:57

2 Answers2

8

You do want revert. The two commands revert and update are complimentary. They both update the files in your working directory, but update also updates the parent revision (see hg parents) whereas revert doesn't. If your parent revision was tip, which it often is, then either would do in this case, but prefer revert.

Example:

ry4an@hail [~/hg/test] % hg stat
? newfile
? output.patch
? this
ry4an@hail [~/hg/test] % hg add newfile
ry4an@hail [~/hg/test] % hg stat
A newfile
? output.patch
? this
ry4an@hail [~/hg/test] % hg revert --all
forgetting newfile
ry4an@hail [~/hg/test] % hg stat
? newfile
? output.patch
? this
Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
2

Any changes to your local copy that have not been committed to the repository can be undone with the command:

hg update -C

That is, update clean.