Remove removed files from Mercurial

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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: