Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not ignore in Laravel storage/app/mydir/myfile.json

I am having a problem with gitignore in Laravel 5.3.

I have the following gitignore file. I used ! to exclude myfile.json.

node_modules/
public/storage
storage/*.key
/.idea
Homestead.json
Homestead.yaml
.env
SQL/
*.sql
mynotes.md
!storage/app/mydir/myfile.json

When I run git status --ignored I get this outputs.

Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    ../.env
    ../SQL/
    ../app/.DS_Store
    ../bootstrap/cache/config.php
    ../bootstrap/cache/services.php
    ../mynotes.md
    ../node_modules/
    uploads/.DS_Store
    ../storage/app/.DS_Store
    ../storage/app/mydir/
...
...

So myfile.json is ignored. How can I write a gitignore so that I can add/commit a file?

like image 829
shin Avatar asked Nov 09 '22 03:11

shin


1 Answers

The rule to remember with gitignore:

It is not possible to re-include a file if a parent directory of that file is excluded.

So check which .gitignore rule actually does ignore ../storage/app/mydir/, because if it is a .gitignore located (for instance) directly in /storage/app/, it will have precedence.

git check-ignore -v -- ../storage/app/mydir/myfile.json

../ means your current .gitignore is not in the right place: for a !storage/app/mydir/xxx rule to apply, it should be in a .gitignore file one folder up.

like image 53
VonC Avatar answered Dec 06 '22 09:12

VonC