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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With