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

rkj picture rkj · Jul 1, 2009 · Viewed 27.1k times · Source

During merges mercurial leaves .orig file for any unresolved file. But after manually resolving problems and marking a file correct it does not delete the .orig file. Can it be automatically removed by some command?

I work on a Mac so I can use something like:

find . -iname '*.orig' -exec rm '{}' ';'

and alias it or something, but I'd rather use something like hg cleanup...

UPDATE:

Since some time now, Purge extension is bundled with Mercurial and solves this problem nicely.

Answer

Martin Geisler picture Martin Geisler · Jul 1, 2009

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.