What is a good way for git .gitignore to exclude files from keeping directories?

there is a project, mainly directory structure definition, there are multiple layers of nesting, I created a README file in each directory, now I need to exclude all files, only README files (or create .gitkeep under the directory), now there are too many directories, is there a good solution?

such as this (if this doesn"t work, you can look at it as pseudo code):

/Dir/*
!/Dir/README
!/Dir/*/README
Git
May.31,2021

feels that the simple method cannot be implemented, so the suffixes except .md in the directory can only be excluded one by one. If the directory is excluded, the * .md is also excluded.


@ Shuai B Yes, it's troublesome. Now we use the multi-directory hierarchical definition gitignore file to solve the problem. That is, each directory defines a gitignore file, excludes all files in the directory, and then excludes gitignore itself and README files (Note: this scheme requires directories to be nested in the directory, and the parent directory should not have useless files as far as possible).


*
!*/
Menu