Nirthakali
Nirthakali

Reputation: 45

How to ignore file with .<numberic>.ext in git?

I have a list of file in my project:

For example:

 1. src/index.1.js
 2. src/screens/index.1.js
 3. src/screens/index.2.js

I want to ignore all the files having the numeric number.

I have tried using **/*.1.* , **/*.2.*. Is there a way to ignore all the file with numeric value?

Upvotes: 1

Views: 132

Answers (3)

Pankaj Singhal
Pankaj Singhal

Reputation: 16053

Git uses glob pattern to match ignored files. Use the following to ignore all such above-mentioned files (with multi-digit numbers also).

**/*.[0-9]*.js

Upvotes: 0

Allan
Allan

Reputation: 12448

Why don't you run the following find command after eventually adapting the \.js part if you do not want to take into account only the .js files:

find . -type f -regextype sed -regex '.*\/.*\.[0-9]\+\.js'
./src/screens/index.2.js
./src/screens/index.123.js
./src/index.1.js

when you find all the files you are interested in, change your find command into:

find . -type f -regextype sed -regex '.*\/.*\.[0-9]\+\.js' -exec git checkout {} \;

to checkout those files.

Upvotes: 0

1615903
1615903

Reputation: 34800

You can use a range. For your example:

**/*.[0-9].js

Would match a js file in any directory that ends with .(number).js

Upvotes: 1

Related Questions