hg remove all files listed in .hgignore

跟風遠走 提交于 2019-11-28 22:47:31

问题


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-*

回答1:


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.




回答2:


From hgrc help

A better example might be:

purge = !$HG status --no-status --unknown -0 | xargs -0 rm

which will make hg purge delete all unknown files in the repository in the same manner as the purge extension.

In order to delete ignored files instead of unknown you have ("hg help status") use --ignored | -i option instead of --unknown



来源:https://stackoverflow.com/questions/19820020/hg-remove-all-files-listed-in-hgignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!