How to automatically remove all .orig files in Mercurial working tree?

Personally, I use

$ rm **/*.orig

if I get tired of the .orig files. This works in Zsh and in Bash 4 after you run shopt -s globstar.

But if you use another shell or want a built-in solution, then maybe you'll like the purge extension (link updated 2016-08-25). That lets you remove all untracked files with

$ hg purge

You can remove all untracked and ignored files with

$ hg purge --all

An advantage of using hg purge is that this will also cleanup directories that become empty after removing the files. The rm command line will just leave the empty directories behind.


btw. find utility has an action -delete so you can type only:

find <path-to-files> -name '*.orig' -delete


If you just want to delete the .orig files, and you happen to be on a Windows computer, the following seems to work well:

D:\workspace>hg purge -I **/*.orig --all

This will delete all untracked files that end in .orig, but won't delete other untracked files, as the other answers would.

You can test this before running it by putting the --print flag in as well.


The following will remove .orig files in your entire working copy hierarchy and also works for paths containing spaces:

find . -name *.orig | while read -d $'\n' file; do rm -v "$file"; done;

I use an alias in my .bash_profile:

alias clearorig='echo "Removing .orig files..."; find . -name *.orig | \
while read -d $'\''\n'\'' file; do rm -v "$file"; done;'

you should use the update hook

update: This is run after an update or merge of the working directory has finished