Home > Enterprise >  How to Ignore or permanently block the files, which contain date or date time in their filenames, fr
How to Ignore or permanently block the files, which contain date or date time in their filenames, fr

Time:07-19

As I mentioned in the Q-title, I have some files whose names contain either date string or date time timestamp in their names which are in the project configured with Git.

File names with dates or timestamps(date time) are like below:

....
....
FileName1_18-07-2022.php
FileName2_18-07-2022_10-28-17_PM.vue
FileNameOther1_18-07-2022_10-28-28_PM.vue
....
....

And there are more than 20s of such files, which I want permanently ignored from Git detection. Filename can have numbers but when they contain exact date format strings(like shown in the examples above) in their names they must not be detected by Git whenever created/modified.

I know there are 2 methods for this, one is .gitignore and other is in Project's .git/info/exclude and I know couple wildcards like * and ?, but can't figure out how to block those files that have date or date time in their names.

Anyone can help figure this out ?

Note: "_PM" or "_AM" are optional and apparently they would be only present if Filename contains full date time string. And date or date time strings will always be in exact pattern as shown in list above. No other pattern of date/date time is there, positively.

CodePudding user response:

Add to your .gitignore:

*_??-??-????[._]*

This will match files with a date followed by a dot or an underscore, and is unlikely to match anything else.

CodePudding user response:

With the help of John Kugelman's answer and some of turek's nice suggestions from comments I came up with a pattern that won't have any issue from year 1000 until year 9999 ;). So this perfectly matches all filename patterns that I have in my project and successfully ignores those files when this pattern is added in either .gitignore or .git/info/exclude file:

*_[0123][0-9]-[01][0-9]-[1-9][0-9][0-9][0-9][._]*.php
*_[0123][0-9]-[01][0-9]-[1-9][0-9][0-9][0-9][._]*.vue

If anyone wants to block all file extensions then they can use this:

*_[0123][0-9]-[01][0-9]-[1-9][0-9][0-9][0-9][._]*.*

Thanks both John and turek for help. Anyone having any suggestions or point-outs feel free to mention in comments below.

  • Related