2

我的 mercurial 存储库中有两个具有相同 .hgignore 文件的分支:dir/

一个分支(开发)应该忽略这个目录,而另一个(发布)不应该忽略它。hg add dir/somefile尽管 .hgignore 文件中有条目,我知道我可以使用。但现在我想递归地添加整个目录。

我搜索并尝试了

hg add dir    # does not add anything
hg add dir*   # does not add anything
hg add dir/   # does not add anything
hg add dir/*  # only adds the files in dir but not in sub-directories
hg add dir/** # only adds the files in dir but not in sub-directories

但这不是递归的。我可以使用add dir/* dir/*/* dir/*/*/*等等,但这很烦人。是否有另一个通配符我必须使用,或者可能是另一种方式来实现这一点?

PS:我想避免更改.hgignore。

4

3 回答 3

6

与此同时,我能够想出——似乎是——一个解决方案:

hg add --dry-run --verbose `hg status --ignored --no-status --exclude **.DS_Store dir/`

这显示了它将添加的文件列表。如果您真的想添加它们,请使用以下命令:

hg add `hg status --ignored --no-status --exclude **.DS_Store dir/`

希望这可以帮助某人。

于 2013-06-21T14:18:01.190 回答
1

如果您有权访问find,则可以执行以下操作:

find docs -exec hg add {} \;

每当使用 find 运行命令时,首先进行空运行总是很好的,所以我通常echo先在命令前面加上一个:

find docs -execechohg add {} \;

如果您需要添加足够多的文件来考虑性能,您可以使用+而不是\;,它将所有匹配的文件名附加到同一命令,而不是为每个文件名运行一次命令。因为hg add这不太可能是一个问题,但它对于理解如何find工作很重要。

find docs -exec hg add {}+

于 2014-04-24T18:27:40.947 回答
0

不幸的是,.hgignore它将忽略不是文件完整路径的任何内容,即使在评估模式时也会受到尊重。StackExchange 上有一个帖子,其中包含您可以使用的替代方案(假设您不想更改.hgignore

于 2013-06-21T13:47:12.577 回答