Имена файлов, имеющие квадратные скобки, НЕ игнорируются .gitignore?

742
MountainMan

Editor1CurrentlyOpen [1] .txt

Так как регулярные выражения не эффективны в файле .gitignore, как глобус может охватывать имена файлов, такие как приведенные выше?

2

1 ответ на вопрос

3
Martin Sugioarto

.gitignoreиспользует выражения glob в каждой строке, поэтому при вводе Editor1CurrentlyOpen[1].txtон будет пытаться найти совпадение Editor1CurrentlyOpen1.txt.

Добавьте обратную косую черту, чтобы замаскировать скобки в записи:

Editor1CurrentlyOpen\[1\].txt 
One can remove the special meaning of '?', '*' and'[' by preceding them by a backslash, or, in case this is part of a shell command line, enclosing them in quotes. Between brackets these characters stand for themselves. Thus, "[[?*\]" matches the four charac- ters '[', '?', '*' and '\'. Ah! found the manpages entry for that. (http://www.unix.com/man-page/Linux/7/glob/) . It had been me trying to write regexes which was both entertaining and frustrating. Now I have to figure out how to automate the .gitignore to add those slashes. MountainMan 7 лет назад 1

Похожие вопросы