I want to ignore everything, except a specific subfolder (and all of its contents!). I tried solutions from possible duplicate questions without any success.
I'd need something simple like:
*
!That/Very/Folder/*
But this is not working
I want to ignore everything, except a specific subfolder (and all of its contents!). I tried solutions from possible duplicate questions without any success.
I'd need something simple like:
*
!That/Very/Folder/*
But this is not working
Your
.gitignore
almost works but it doesn't for a simple reason: the first rule (*
) tells Git to ignore every file and directory in the root of the repository. Git honors it and ignores everything, including theThat
directory and its content. The "unignore" rules that follow do not match anything inside theThat
subdirectory because theThat
directory is ignored together with it content, and they don't have effect.In order to tell Git to not ignore files and directories in a deeply nested sub-directory you have to write ignore and unignore rules to let it reach the enclosing sub-directory first and then add the rules you want.
Your
.gitignore
file should look like this:add the folder to the gitignore
force folder to be added to the repository
EDIT:
I use this solution for example when I need to keep log folder, for example, but not its content. Generally, when I suppose the content of the folder is never to be added. And generally I add just
path/to/folder/.gitkeep
file with-f
option.Ignore everything, allow subfolders (!), then allow specific folder contents (with unlimited subfolders within).
Credits to @Jepessen for the middle piece that makes it work.