Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg remove all files listed in .hgignore

I have a mercurial repo with .hgignore file. I want to remove all files from disk (hg remove) in this repo which match pattern(s) listed in .hgignore.

I can list all ignored files with hg status -i but I don't know how can I delete them.

.hgignore contents:

syntax: glob

build
\.egg*
*.pyc

.DS_Store
*.sublime-*
like image 385
Umair A. Avatar asked Nov 06 '13 18:11

Umair A.


People also ask

How to remove files from hg?

Once you decide that a file no longer belongs in your repository, use the hg remove command. This deletes the file, and tells Mercurial to stop tracking it (which will occur at the next commit). A removed file is represented in the output of hg status with a “ R ”.

How do I get rid of HG delete?

To undo added files, see hg forget. -A/--after can be used to remove only files that have already been deleted, -f/--force can be used to force deletion, and -Af can be used to remove files from the next revision without deleting them from the working directory.


1 Answers

You can only run hg remove on files that are tracked. To remove tracked files that match the .hgignore patterns, run this command

$ hg forget "set:hgignore() and not ignored()"

This uses a fileset to select the right files.

If you want to remove files that are already ignored by Mercurial (not tracked), then see the purge extension. That can be used to cleanup a working copy so that it looks like a fresh checkout.

like image 102
Martin Geisler Avatar answered Oct 28 '22 22:10

Martin Geisler