tags:

views:

58

answers:

2

I forget to place the correct .hgignore into my project and am now confronted with many useless files in my repository. As these files are already under source control .hgignore will not pick em up.

Is there a way for hg to forget all files matched by .hgignore?

A: 

You need to remove that file for it to be ignored.

hg remove -Af myfile

(remove from the revision while leaving a copy on your workspace: or hg forget)

But your Mercurial repository won't "forget" those same files in the previous revisions.

Removing a file does not affect its history.
It is important to understand that removing a file has only two effects.

  • It removes the current version of the file from the working directory.
  • It stops Mercurial from tracking changes to the file, from the time of the next commit.

Removing a file does not in any way alter the history of the file.


Another way, when you have a lot of extra files you need now to ignore is:

  • remove them (from the file system, not with an hg command, but with an OS 'rm' command)
  • hg addremove (warning, it will add currently non-committed files, but it will hg remove all the other files you just rm'ed)

See How to forget all removed files with Mercurial for more.

VonC
Yes I am aware that I can do it manually but I want to apply the .hgingore patterns again on my files to forget all files that match. There are several hundred CVS folders and classes I want to get rid of.
OliverS
@OlivierS: I understand. I have updated my answer to better address your case.
VonC
+1  A: 

I don't think hg can do it out of box.

But it's pretty easy to roll your own. hgignore entries are regexp or glob, so you can just go through the entries and find the matching files/dirs and do "hg remove" on them.

For hgignore parsing/matching, if you use python you can just call the functions in hg's ignore.py.

Maybe someone can write an extension for this.

Geoffrey Zheng
I came to the same conclusion and gave it try but only for like 20min. No success yet but I found the important calls in dirstate class. The hg API lacks documentation.
OliverS
They deliberately made it so, it seems, probably because it's changing too fast: "The Mercurial API is intended primarily for internal use and creation of extensions and is subject to change at any time" (from http://mercurial.selenic.com/wiki/MercurialApi). The hg code is pretty clean once you get used to it.
Geoffrey Zheng