Git Ignore everything in a directory except subfolders

大城市里の小女人 提交于 2019-11-30 05:43:18

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.

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
!*/

Try this:

*.*
!.gitignore
!*/*
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!