I have the following .gitignore:
# Ignore everything
/*
!/.gitignore
# Readd folders:
#!/mainfolder/ # this works!
!/mainfolder/subfolder/
!/mainfolder/subfolder/*
I want to ignore everything, but subfolder/
. Adding the line !/mainfolder/
works, so that /mainfolder is not ignored anymore. But I want to add only the things below subfolder/
and the second and third lines for subfolder/
do not work.
I have found several links online suggesting this is the correct way (eg this one ). So what am I doing wrong?!
EDIT: I am using Git 2.17.1 from SourceTree on Windows 10. I have tested these results from the integrated MINGW64 bash.
You need to whitelist folders first, then files:
*
!.gitignore
!/mainfolder/
/mainfolder/*
!/mainfolder/subfolder/
!/mainfolder/subfolder/**
For any file still ignored, check why with:
git check-ignore -v -- path/to/ignored/file
would it be possible to extend the answer on how you would do this for a deeper subfolder? Eg how would I ignore everything except ´deepsubfolder´(?): !/mainfolder/subfolder/deepsubfolde
That is similar to " Git - Unignore any folder located anywhere inside repository that recursively allows everything ":
*
!.gitignore
!*/
!**/deepsubfolder/**
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.