Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignore: How to match one or more digits

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?

like image 701
Reina Abolofia Avatar asked Aug 28 '15 02:08

Reina Abolofia


1 Answers

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.
like image 113
Thomas Lee Avatar answered Sep 28 '22 13:09

Thomas Lee