[英]How to hg ignore filename with no extension?
Mercurial can be configured to ignore files whose filename have a certain extension. 可以将Mercurial配置为忽略文件名具有特定扩展名的文件。 For example, *.txt
files can be ignored by adding this to ~/.hgignore
: 例如,可以通过将此添加到~/.hgignore
来忽略*.txt
文件:
syntax: glob
*.txt
How can I setup my .hgignore file to ignore files whose filenames have no extensions ? 如何设置我的.hgignore文件以忽略文件名没有扩展名的文件? For example, files named foobar
and abracadabra
should be ignored, but foobar.cpp
and abracadabra.c
should be tracked. 例如,应忽略名为foobar
和abracadabra
文件,但应跟踪foobar.cpp
和abracadabra.c
。
Use regexp
syntax instead since it's not possible with glob
: 使用regexp
语法,因为它不可能与glob
:
syntax: regexp
^[^.]+$
PS: you can add it right after your syntax: glob
section PS:您可以在syntax: glob
后立即添加syntax: glob
部分
If you have a small list of files without extension that you want to ignore, then you can just list them as glob patterns: 如果你有一个没有扩展名的小文件列表要忽略,那么你可以将它们列为glob模式:
syntax: glob
foobar
abracadabra
If you want to ignore all files without an extension, then things become more difficult. 如果你想忽略没有扩展名的所有文件,那么事情会变得更加困难。 If you use the regexp provided by zerkms, 如果你使用zerkms提供的正则表达式,
syntax: regexp
^[^.]+$
then you will also ignore directories without an "extension", that is directories without .
那么你也将忽略目录 ,而“分机”,即目录没有.
in their names such as src
, and so on. 在他们的名字,如src
,等等。
Because Mercurial matches files and directories top-down while traversing your working copy, and because it doesn't distinguish between files and directories when matching against the patterns in the .hgignore
file, you cannot include a directory while ignoring files with the same name. 因为Mercurial在遍历工作副本时自上而下匹配文件和目录,并且因为它与.hgignore
文件中的模式匹配时不区分文件和目录, 所以在忽略具有相同名称的文件时不能包含目录。
(You can simulate the opposite: by ignoring foobar/
in regexp syntax you end up ignoring all files inside foobar/
while not ignoring a file named foobar
in another directory.) (您可以模拟相反的情况:通过忽略foobar/
in regexp语法,您最终会忽略foobar/
所有文件foobar/
而不会忽略另一个目录中名为foobar
的文件。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.