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

shi*_*hin 5 gitignore laravel-5.3

我在 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
Run Code Online (Sandbox Code Playgroud)

当我运行时,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/
...
...
Run Code Online (Sandbox Code Playgroud)

所以 myfile.json 被忽略。如何编写 gitignore 以便我可以添加/提交文件?

Von*_*onC 2

使用 gitignore 时要记住的规则:

如果排除某个文件的父目录,则无法重新包含该文件

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

git check-ignore -v -- ../storage/app/mydir/myfile.json
Run Code Online (Sandbox Code Playgroud)

../意味着您当前的位置.gitignore不正确:要!storage/app/mydir/xxx应用规则,它应该位于.gitignore上一级文件夹的文件中。