Git Ignore everything in a directory except subfolders

前端 未结 3 446
陌清茗
陌清茗 2020-12-29 01:58

This is my folder structure:

data/
    .gitignore
    uploads/
        .gitignore

I would like to commit the folders but not the files insi

相关标签:
3条回答
  • 2020-12-29 01:59

    Try this:

    *.*
    !.gitignore
    !*/*
    
    0 讨论(0)
  • 2020-12-29 02:08

    The solution is quite easy, add !*/ to the .gitignore files and only files in the current folder will be ignored

    # Ignore everything in this directory
    *
    # Except this file
    !.gitignore
    # Except folders
    !*/
    
    0 讨论(0)
  • 2020-12-29 02:12

    Please don't misuse .gitignore files. Better stick to default ways to go on this, so later developers can quickly get into your project.

    1. Add an empty .gitkeep file in the folders that you want to commit without the files
    2. Exclude the folders, but not the .gitkeep from your main .gitignore file.

      folder/*
      !folder/.gitkeep
      

    This ignores all files in a folder, but not the .gitkeep file. Now the folder will be commited with only the .gitkeep file as content.

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