How to git ignore subfolders / subdirectories?

后端 未结 10 1158
孤街浪徒
孤街浪徒 2020-11-28 00:30

I have a lot of projects in my .Net solution. I would like to exclude all \"bin/Debug\" and \"bin/Release\" folders (and their contents), but still include the \"bin\" folde

相关标签:
10条回答
  • 2020-11-28 00:58

    For ignoring subfolders but not main folder I could only get this to work in Visual Studio Code by placing a dummy readme.txt in the main folder. Only then /*/ checked in the main folder (and no subfolders).

    0 讨论(0)
  • 2020-11-28 01:03

    All the above answers are valid, but something that I don't think is mentioned is that once you add a file from that directory into the repo, you can't ignore that directory/subdirectory that contains that file (git will ignore that directive).

    To ignore already added files run

    $ git rm --cached
    

    Otherwise you'll have to remove all files from the repo's target directory first - and then you can ignore that folder.

    0 讨论(0)
  • 2020-11-28 01:07

    Besides putting the correct entries in your .gitignore file, if you're trying to ignore something already added to the repo, you have to do git rm -r /path/to/dir and commit that before you add the dir to your .gitignore file. Otherwise the only thing git will ignore is your ignore directive.

    0 讨论(0)
  • 2020-11-28 01:08

    You can use .gitignore in the top level to ignore all directories in the project with the same name. For example:

    Debug/
    Release/
    

    This should update immediately so it's visible when you do git status. Ensure that these directories are not already added to git, as that will override the ignores.

    0 讨论(0)
提交回复
热议问题