Does Mercurial have an equivalent to git clean?

20,002

Solution 1

There is no equivalent to git clean in the core Mercurial package.

However, the hg purge extension does what you are after.

There is an open issue to make this extension part of the core package.

Solution 2

The extension is already included in mercurial, but you still have to activate it.

It's as simple as creating a .hgrc file in your home directory (e.g. Win 7: C:\Users\«yourusername»\.hgrc) and adding the following content to that file:

[extensions] 
purge =

(Home directory is ~/.hgrc for most other desktop operating systems (Unix, Gnu/Linux, Mac osx, BSD, etc.)

Solution 3

I don't use git for my repository management. However, if I were to guess, I think hg purge might be what you are seeking.

Solution 4

If you are on a linux based system (or Windows cygwin) you can:

hg status | grep "^?" | xargs rm -rf

If this works you can put this in your ~/.hgrc:

[alias]
clean = !hg status | grep "^?" | xargs rm -rf

Then simply run:

hg clean

I tested this on windows using cygwin (should work on linux).

Share:
20,002
Erik B
Author by

Erik B

Professional iPhone and iPad developer. I have some of Sweden's most downloaded apps on my resume. #SOreadytohelp

Updated on February 23, 2020

Comments

  • Erik B
    Erik B over 4 years

    hg clean does not seem to exist, which kinda bothers me. Is this a feature that Mercurial doesn't have or did they just name it differently?

  • Tim Post
    Tim Post about 14 years
    The extension wiki page says "This extension is currently being distributed along with Mercurial.". I've had it installed since it was published .. I'm not sure what version has or (will) introduce it.
  • Tim Henigan
    Tim Henigan about 14 years
    Based on the issue tracker, it sounds like the feature was removed in v1.1.2 because "people that play with hg purge can delete files that they need". The issue was last updated in May 2009, so it has gotten stale. I would certainly vote to put it back in.
  • Tim Post
    Tim Post about 14 years
    1.1.2 ships it, not sure about previous versions.
  • Anonigan
    Anonigan about 14 years
    Why not make -n the default, and require -f to actually delete files, like git clean does from some time?
  • Sharpie
    Sharpie almost 14 years
    And why not make it restricted to the current directory and below like git clean? I got a nasty surprise the first time I ran hg purge.
  • FelipeC
    FelipeC over 11 years
    That doesn't cover files that are not tracked; git clean -fxd.
  • MGP
    MGP almost 11 years
    No need for grep. clean = !hg status -un0 | xargs -0 rm
  • MIWMIB
    MIWMIB about 10 years
    Even though this extension is included, you still have to activate it before using it. It's as simple as creating a .hgrc file in your home directory (e.g. Win 7: c:\Users(yourusername)\.hgrc ) and adding the following content: [extensions] purge =
  • Benjohn
    Benjohn over 8 years
    Just for a tiny bit of extra clarity on @FrankGorman's comment, add [extensions] purge = to your ~/.hgrc file.