简体   繁体   中英

How to hg ignore filename with no extension?

Mercurial can be configured to ignore files whose filename have a certain extension. For example, *.txt files can be ignored by adding this to ~/.hgignore :

syntax: glob
*.txt

How can I setup my .hgignore file to ignore files whose filenames have no extensions ? For example, files named foobar and abracadabra should be ignored, but foobar.cpp and abracadabra.c should be tracked.

Use regexp syntax instead since it's not possible with glob :

syntax: regexp
^[^.]+$

PS: you can add it right after your syntax: glob section

If you have a small list of files without extension that you want to ignore, then you can just list them as glob patterns:

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,

syntax: regexp
^[^.]+$

then you will also ignore directories without an "extension", that is directories without . in their names such as src , and so on.

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.

(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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM