Git-ignore certain files in sub-directories, but not all

后端 未结 3 1687
故里飘歌
故里飘歌 2020-12-24 10:28

I have a structure similar to the following:

/root/
/root/data/
/root/data/script.php
/root/data/some.json
/root/data/feature/one.json
/root/data/feature/tw         


        
相关标签:
3条回答
  • 2020-12-24 10:45

    you can place data/**/*.json in your .gitignore in /root directory to prevent multiple .gitignore files in different directories

    **/ - matches any count of subdirectories (including current)

    example: data/**/*.json record will ignore data/1.json, data/subfolder/2.json, data/../../3.json

    0 讨论(0)
  • 2020-12-24 10:55

    I've written a post about such problem recently. See here.

    Basically what you need is to put one .gitignore with *.json in the /data/ directory.

    UPD: Since git 1.8.4 (1.8.2 if you're using msysgit) it is possible to use double-star patterns, like /data/**/*.json

    0 讨论(0)
  • 2020-12-24 11:04

    This pattern work for me for data subfolder ignoring only png and jpg files:

    **/data/**/*.png
    **/data/**/*.jpg
    
    0 讨论(0)
提交回复
热议问题