如何在 Laravel storage/app/mydir/myfile.json 中不忽略

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

我在 Laravel 5.3 中遇到 gitignore 问题。

我有以下 gitignore 文件。我用 ! 排除了 myfile.json.

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

当我 运行 git status --ignored 我得到这个输出。

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/
...
...

所以myfile.json被忽略了。我怎样才能写一个 gitignore 以便我可以 add/commit 一个文件?

使用 gitignore 时要记住的规则:

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

所以检查哪个 .gitignore 规则实际上忽略了 ../storage/app/mydir/,因为如果它是 .gitignore 直接位于(例如)/storage/app/,它将具有优先权.

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

../ 表示您当前的 .gitignore 不在正确的位置:要应用 !storage/app/mydir/xxx 规则,它应该在 .gitignore 文件中向上一个文件夹.