Remove removed files from Mercurial

Just do an “hg addremove”, doh!

When you do “hg status” at the command line, files that are missing are marked with a leading “!”. To actually remove them from the repository you do a “hg remove X”, where X is the file.

I found it annoying to do this on the command line, so I searched for my shell mojo (via Cygwin on win7) and came up with this:

hg st | grep “^!” | sed “s/! (.*)/”1″/” | xargs hg remove

Wait … I now know that there is a command to already do this, “hg addremove”

I must have missed this, even after nth times of doing hg –help. Oh well … Got some practice with Linux tool use.

This is from the hg man page; note, I removed some details:


hg addremove [OPTION]… [FILE]…

Add all new files and remove all missing files from the repository.

New files are ignored if they match any of the patterns in .hgignore. As with add, these changes take effect at the next commit.


Returns 0 if all files are successfully added.

-s, –similarity
guess renamed files by similarity (0<=s<=100)
-I, –include include names matching the given patterns
-X, –exclude exclude names matching the given patterns
-n, –dry-run do not perform actions, just print output

Further Reading

Leave a Reply

Your email address will not be published. Required fields are marked *