Git ignore: How to match one or more digits

淺唱寂寞╮ 提交于 2019-11-29 19:51:54

问题


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

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.

Is there a way to tell the gitignore file to match one or more digits?


回答1:


Sadly but .gitigore use glob instead of regex for matching, which means there's not a good way to do it.

Otherwise, Git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag ...

Of course you can use:

*.log.[0-9]*

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.


来源:https://stackoverflow.com/questions/32262412/git-ignore-how-to-match-one-or-more-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!