Can Mercurial use .hgignore to forget files?
I forget to place the correct .hgignore into 开发者_JS百科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?
filesets awesomeness (requires 1.9):
hg forget "set:hgignore() and not ignored()"
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 willhg remove
all the other files you just rm'ed)
See How to forget all removed files with Mercurial for more.
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.
This is what I did for each of the directories mentioned in .hgignore
for /f "delims=" %i in ('dir bin /ad/s/b') do hg forget %i/
And for files
for /f "delims=" %i in ('dir *.user /s/b') do hg forget %i
DISCLAIMER:
I don't know if it will work on non-windows OS or not.
Idan K's solution is great. I added an alias to my global mercurial.ini because I can't remember the command.
[alias]
forgetignored = forget "set:hgignore() and not ignored()"
精彩评论