Reverting Dirty Files

posted by Ryan Wilcox on November 30, 2009

So you have a change you don’t want to keep. Example:

$ hg status
M fileone.txt
M filetwo.txt

Upon reviewing your changes you find out that filetwo.txt is junk you want to get rid of. You could go into the file and manually remove your changes, but Mercurial gives you a better tool for this: hg revert

$ hg revert filetwo.txt

If you have many files that have changes (for example, you want to throw away all your work and start again), use the --all command:

$ hg revert --all
reverting fileone.txt
reverting filetwo.txt

This works like the git reset --hard HEAD^ command, for those of you familiar with git.

You’ve made some changes you don’t want to commit, here’s how to clear them out.