Search code examples
mercurial

Mercurial equivalent of git reset HEAD, or the inverse of hg addremove?


I just moved a bunch of files from one directory to another. I also created several new files. And I ran python setup.py sdist, which generates a bunch of files.

I forgot to add all these files I do not care about to my .hgignore so when I ran hg addremove - bam, I get everything.

Ick.

In git, I would run git reset which would simply unstage all of my changes and life would be happy. In TortoiseHg I could just click the little checkbox a couple of times to uncheck all of them and life would also be happy.

But on the command line... I just want to go back to the way things were before I did hg addremove.

How do I do that?


Solution

  • It's possible to undo add 'adds' and 'removals' in two steps. First, to undo 'adds':

    hg forget "set:added()"
    

    Undoing removals is a bit more tricky, because if we just hg revert the files marked as removed, like `hg revert "set:removed()", these files will pop back in the working directory. This is probably not what you want, so let's delete them right after they are reverted, for Linux it would be something like:

    hg locate "set:removed()" | xargs -I % sh -c 'hg revert "%"; rm "%"'