Gitignore file with custom ext

Hello,

I have git tracked files problem
test.php
index.php
index.php_back
index.php07.2021
foo.js

all files that have a .php extension, but those .php_back .php072021, etc. I do not want

here is terminal command that work
find .|grep -e β€œ.php$”
But in .gitignore file this regex pattern do not work.

Any help, please.

Hi,

This question should probably be in the β€˜Git’ category.
In your .gitignore file, you could list the extensions using a wildcard.
For example, your gitignote file could look like:

*.php_back
*.php07.2021

This will exclude all files that end with these extensions.

Hope that helps.

thanks.
this cannot help because mutated extensions appear dynamically.
For example test.php1 test.php2 test.php555
That’s why I’m looking for a solution with regex in gitignore.

Sorry - I understand now.

Are you able to dynamically generate a double extension?
For example, you could use index.php_back.phpD.
In this case, the wildcard would work because you could ignore all β€˜phpD’.

This also might help with running the script as otherwise, your PHP parser would need to know each extension to use for PHP.

thank again.
Here solution:
*[.php, .js, .bin]*
!*[.php, .js, .bin]
This works with multiple file ext. And this is not actually regex. gitignore regex. :slight_smile: :grinning: :- :wink:

1 Like