Git忽略:如何匹配一个或多个数字 [英] Git ignore: How to match one or more digits
问题描述
我想确保git忽略轮流创建的任何日志文件.例如
I would like to make sure that git ignores any log files that are created on a rotating basis. For instance
debug.log
debug.log.1
debug.log.2
debug.log.10
应该全部忽略.我当前正在使用*.log
和*.log.[0-9]
来忽略列表中的前3个.要捕获第三个,我知道我可以使用*.log.[0-9][0-9]
.但是,我更希望找到一个可以捕获所有这些信息的单一解决方案.
should all be ignored. I am currently using *.log
and *.log.[0-9]
to ignore the first 3 in the list. To capture the third, I know I could use *.log.[0-9][0-9]
. However, I'd prefer to find a one line solution that could capture all of these.
有没有办法告诉gitignore文件匹配一个或多个数字?
Is there a way to tell the gitignore file to match one or more digits?
推荐答案
可悲的是,.gitigore
使用 glob 而不是使用正则表达式进行匹配,这意味着没有一个很好的方法.
Sadly but .gitigore
use glob instead of regex for matching, which means there's not a good way to do it.
否则,Git会将模式视为适合Fnmatch(3)使用FNM_PATHNAME标志使用的shell球...
Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag ...
您当然可以使用:
*.log.[0-9]*
但是请注意,这也将与debug.log.9abc
之类的东西匹配.如果您对此表示满意,我认为这种模式就足够了.
But notice this will also match something like debug.log.9abc
. If you are okay with that, I think this pattern will be enough.
如果您真的必须严格执行此操作,是的,您必须将它们全部列出:
If you REALLY have to do it strictly, yes you have to list them all:
*.log
*.log.[0-9]
*.log.[0-9][0-9]
*.log.[0-9][0-9][0-9]
# ... And so on if needed.
这篇关于Git忽略:如何匹配一个或多个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!