Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand for multiple file extensions in.gitignore

Tags:

git

gitignore

Is there a Bash script-like shorthand for matching multiple different extensions in a .gitignore file such as:

*.{bak,save,aux,nav,toc}

?

The syntax above definitely does not work.

like image 679
Jason Avatar asked Jan 11 '18 09:01

Jason


1 Answers

The method mentioned in the other answer, *[.bak, .save, .aux,. nav, .toc], does not work. Or at least, not as expected. It actually selects much more than just those extensions.

As far as I can tell, there is no way to do this, unless the extensions you want to ignore are all a single character long.

According to Git's documentation:

"[]" matches one character in a selected range

As can be seen in the example later on that page:

# ignore objects and archives, anywhere in the tree.
*.[oa]

This would ignore any .o or .a files.

So this means that a pattern like *[.ext, .txt, .bin] will behave identically to *[beintx., ] (which is just the same pattern with duplicate characters removed and sorted) and will ignore any file ending in (including extension) any one of those nine characters.

I just tried this out on a Git repository of my own and it does indeed seem to follow this behavior.

like image 114
Mogzol Avatar answered Sep 20 '22 11:09

Mogzol