Ignoring everything in .gitignore and adding subfolder does not work

匿名 (未验证) 提交于 2019-12-03 01:35:01

问题:

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 (e.g. 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.

回答1:

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

That is similar to "Git - Unignore any folder located anywhere inside repository that recursively allows everything":

* !.gitignore !*/ !**/deepsubfolder/**


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