tags:

views:

535

answers:

4

Is it possible to delete all untracked files from my working directory? Let's say I added a bunch of files to my working directory, didn't add them via hg add, and now want to get rid of those new files completely?

Thank you.

UPDATE:

Thank you guys for linux tips, unfortunately, I'm on windows, although I'm using PowerShell, so combined solution is also possible here.

END UPDATE.

+13  A: 

Add the Mercurial Extension called purge. It is distributed by Mercurial.

This extension adds a “purge” command to “hg” that removes files not known to Mercurial. i.e. untracked Files. So your command would be,

hg purge

It is not enabled by default, maybe to avoid accidentally removing files that you forgot to add.

To install this extension, add this to your mercurial settings file (.hgrc on Unix, Mercurial.ini on Windows)

[extensions]
purge =
simplyharsh
Nice, did not know about this.. You can enable by adding the following section to you .hgrc:[extensions]hgext.purge=
Kristian
To enable it, add the line "purge = " under [extensions], as specified here: http://mercurial.selenic.com/wiki/UsingExtensions
wsorenson
A: 

This should do the trick:

hg status | grep '^\?' | sed 's/^\? //' | xargs rm -rf
Kristian
A: 

Assuming that you are using a *nix system you could run something like this:

rm `hg st | awk '/\?/ {print $2}'`

from the root of the mercurial repository.

I don't know of a standard mercurial command to achieve the same but I believe there are many more command-line options to do this. I'm sure there are "better" solutions and would be interested to hear any other suggestions.

Please use this command with caution as it was not thoroughly tested.

Heinrich Filter
+4  A: 

The proper way without purge is:

hg st -un0 |xargs -0 rm

tonfa