How to forget all removed files with Mercurial

I am new to Mercurial and after a cleanup of the image folder in my project, I have a ton of files showing with ! in the 'hg status'. I can type a 'hg forget ' for each, but there must be an easier way.

So how can I tell mercurial to forget about all the removed (status = !) files in a folder?


If you're also okay with adding any files that exist and aren't ignored then:

hg addremove

would a popular way to do that.

With fileset (Mercurial 1.9):

hg forget "set:deleted()"

In general, on Linux or Mac:

hg status -dn | while read file ; do hg forget "$file" ; done

Or, if your shell allows it, if there are not too many files, and if the filenames do not contain spaces or special characters, then:

hg forget $(hg st -dn)


You can try:

hg forget -I '*'

in order to include all files in your forget command.

By using the -d flag for status, which displays missing files:

for file in $(hg status -d | cut -d " " -f 2); do echo hg forget $file; done

Run this in the root of your repo, and if you're happy with the results, remove the echo

This has the bonus over the accepted answer of not doing any additional work, e.g. adding a bunch of untracked files.

more shorter instead of

for file in $(hg status -d | cut -d " " -f 2); do echo hg forget $file; done


hg status -d | cut -d " " -f 2 | xargs echo hg forget # test case
hg status -d | cut -d " " -f 2 | xargs hg forget # real work

Need Your Help

Mock File methods in .NET (like File.Copy("1.txt", "2.txt"))

.net unit-testing mocking

We have some methods that call File.Copy, File.Delete, File.Exists, etc. How can we test these methods without actually hitting the file system?

Pass an array of integers to ASP.NET Web API?

c# arrays rest

I have an ASP.NET Web API (version 4) REST service where I need to pass an array of integers.