Search code examples
gitlaravelgitignore

git, ignore files with a pattern in Laravel


I have this .gitignore file:

/node_modules
/public/storage
/public/hot
/storage/*.key
/vendor
.idea
Homestead.json
Homestead.yaml
.DS_Store
Thumbs.db
*.sublime-project
*.sublime-workspace
.project
/nbproject
_ide_helper.php
composer.phar
error.log
Todo.rtf
.vagrant
/.vagrant
npm-debug.log
.env
/public/css/backend.css
/public/css/frontend.css
/public/js/backend.js
/public/js/frontend.js
/public/mix-manifest.json
/public/mix.js

Right now I'm ignoring last lines (starting with /public/...) but they are specific files. In my project I have a lot of compiled files like:

/public/css/backend.345346n345jkn3454.css
/public/css/frontend.679nkj67n9n79n679.css
/public/js/backend.2345b34j5bn345m34..js
/public/js/frontend.234234234n234f.js
/public/mix-manifest.json
/public/mix.9b87a1da741f957f3f09.js

Etc... so I want to include all the files that has the "backend", "frontend" and "mix" text in the beginning of the name. It is possible to do something like this?:

/public/css/backend*.css
/public/css/frontend*.css
/public/js/backend*.js
/public/js/frontend*.js
/public/mix*.js

I did that but it doesn't work, so I don't know how to do it.

EDIT: This question is not about ignoring already commited files on a repository. I wanted to know the use of wildcards for my specific situation.


Solution

  • Yup. You can use this syntax in you .gitignore. Probably you are trying to ignore something that is already committed, though.

    To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename

    To untrack every file that is now in your .gitignore:

    First commit any outstanding code changes, and then, run this command:

    git rm -r --cached .
    

    This removes any changed files from the index(staging area), then just run:

    git add .
    

    Commit it:

    git commit -m ".gitignore is now working"
    

    To undo git rm --cached filename, use git add filename.

    You can read more here, and here.