Git's .gitignore does not work with one or more asterisk qualifier + -


this question has answer here:

$ git version git version 2.9.3.windows.1 

i seem having trouble + (one or more) pattern matcher in .gitignore. here test + , *used pattern qualifier digits embedded in file name. want keep test.txt in source control , ignore test[0-9]+.txt files.

directory:

$ ll | grep test -rw-r--r-- 1 asdf 1049089      0 apr  5 15:55 test.txt -rw-r--r-- 1 asdf 1049089      0 apr  5 15:55 test123.txt -rw-r--r-- 1 asdf 1049089      0 apr  5 15:55 test1235.txt -rw-r--r-- 1 asdf 1049089      0 apr  5 15:55 test124.txt 

git ignore file contents test 1:

test[0-9]+.txt 

test 1:

$ git status | grep test     test.txt     test123.txt     test1235.txt     test124.txt 

this should have filtered out 2nd through 4th files.

git ignore file contents test 2:

test[0-9]*.txt 

test 2:

$ git status | grep test     test.txt 

this should have filtered out of files.

why happening?

the .gitignore file using globbing, not regular expressions. using + not valid.

so second attempt closer want.

test*.txt 

this filter out files starting test , ending .txt in between. catch test.txt because * in glob can zero-width.

what have may simplest option.

test[0-9]*.txt 

that match test followed digit, followed (including nothing), followed .txt.

so imperfect, in match on

test1foo.txt 

which has non-numeric text past digit. how specific requirement dictate this. can add few patterns, like

test[0-9].txt test[0-9][0-9].txt test[0-9][0-9][0-9].txt test[0-9][0-9][0-9][0-9].txt test[0-9][0-9][0-9][0-9][0-9].txt 

if have sure it's digits, pick how many digits, , use multiple entries make specific match.


Comments