Mercurial 如何忽略包含已添加到源代码管理的文件的子文件夹

Mercurial how to ignore subfolder containing files already added to source control

我有一个结构如下的项目

project_dir/
  WebContent/
    es5/
    ...
  src/ 
  ...
  .hgignore  

我尝试使用以下模式忽略 WebContent/es5 目录下的所有内容:

syntax: glob
WebContent/es5/**

syntax: regexp
^WebContent/es5

syntax: regexp
^WebContent/es5$

仍在跟踪文件夹中已修改的文件。有人可以帮我吗?

线索在忽略文件的 documentation 中:

The Mercurial system uses a file called .hgignore in the root directory of a repository to control its behavior when it searches for files that it is not currently tracking.

如果您已将子目录中的文件添加到存储库(明确地或在将模式添加到 .hgignore 文件之前),mercurial 会记住它,直到您 hg forget 它。

% hg init foo

% cd foo

% ls

% mkdir sub

% cat <<EOF > .hgignore
^sub/
EOF

% touch a

% touch sub/b sub/c

% hg st
? .hgignore
? a

% hg add sub/b

% hg st
A sub/b
? .hgignore
? a

% hg forget sub
removing sub/b

% hg st
? .hgignore
? a

documentation 中给出了一个示例,说明如何忘记被 .hgignore 排除的所有文件:

   - forget files that would be excluded by .hgignore:

        hg forget "set:hgignore()"