Reputation: 2696
This question must have been asked before, but I was not able to find an answer.
I want to use .gitignore
to ignore all of the following files:
dsmodelext.c
dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext107.c
Currently I put four lines in my .gitignore
file:
dsmodelext.c
dsmodelext[0-9].c
dsmodelext[0-9][0-9].c
dsmodelext[0-9][0-9][0-9].c
Is there a way to express the same on a single line?
Upvotes: 6
Views: 2725
Reputation: 6717
given the files
dsmodelext.c
dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext2x3.c
dsmodelext107.c
dsmodelext107foo.c
The glob pattern dsmodelext*[0-9].c
would match
dsmodelext1.c
dsmodelext2.c
dsmodelext23.c
dsmodelext2x3.c
dsmodelext107.c
For some of these number usecases this is a good enough approximation.
Upvotes: 2
Reputation: 14060
Gitignore takes it's syntax from fnmatch/glob, which is specified in man glob(7).
There doesn't seem to be a way to indicate a certain number of characters need to be matched, like you could with the regular expression dsmodelext[0-9]{0,3}.c
You could decide to be lenient and just defined dsmodelext*.c
to be ignored.
Upvotes: 5