Difference between ** and * in glob matching (.gitignore)

前端 未结 3 1396
Happy的楠姐
Happy的楠姐 2021-02-12 13:32

I have the following directory structure and files.

pw-spec/
|-- event_spec.coffee
|-- event_spec.js
|-- integration
|   `-- service
|       |-- auth_spec.coffee         


        
相关标签:
3条回答
  • 2021-02-12 14:05

    Create a .gitignore in pw-spec in which you insert these two lines:

    *.js
    */*.js
    

    Also note that if you already have files tracked in this subdirectory which you want "untracked", you have to make them unknown to the index as such:

    git rm --cached path/to/file
    

    For instance, if in directory pw-spec you can do:

    find -type f -name "*.js" | xargs git rm --cached
    
    0 讨论(0)
  • 2021-02-12 14:13

    There are two approaches for this type of situation, depending on your needs.

    One solution is to put

    # generated files
    *.js
    

    in pw-spec/.gitignore.

    The second solution is to put:

    /pw-spec/*.js
    /pw-spec/*/*.js
    /pw-spec/*/*/*.js
    

    and so forth in the main .gitignore file.This approach is brittle if more sub-directories are added.

    I generally prefer to put the .gitignore file at the same level as the Makefile which generates the files that I am ignoring.

    0 讨论(0)
  • 2021-02-12 14:26

    The difference is that ** doesn't work, at least not for everyone. See

    Why doesn't gitignore work in this case?

    You can have a separate .gitignore in pw-spec/

    0 讨论(0)
提交回复
热议问题