Git ignore: How to match one or more digits

前端 未结 1 1782
傲寒
傲寒 2021-01-02 06:19

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


        
相关标签:
1条回答
  • 2021-01-02 07:05

    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.
    
    0 讨论(0)
提交回复
热议问题