Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

.gitignore: Is it possible to use regex pattern to match at least one more character

My website’s .htaccess was not in git, I have a rule to ignore it:

.htaccess*  

Because I have these files

.htaccess
.htaccess.local
.htaccess.online
.htaccess.testsite

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So I use * in .gitignore. Besides, sometimes

.htaccess_local.txt
.htaccess_online.txt

So, one * can do this.

Now I would like to add .htaccess, but still ignore others. I tried

.htaccess(.)+

It seems not working.

>Solution :

.htaccess(.)+ doesn’t work because .gitignore doesn’t use regular expression syntax; it uses shell wildcard (fnmatch) syntax.

I see 2 ways to fix your problem. The simplest is to continue ignoring .htaccess* but force add one file (forced adding allows to add ignored files):

git add --force .htaccess

Tracked files are never ignored even if they match .gitignore patterns.

The second way if to ignore all files and unignore the one:

.htaccess*
!.htaccess
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading