nadlie nadlie - 1 year ago 72
Git Question

Git exclude all files that match a name in all folders expect folders named Views

I want to exclude all file named Web.config from every folder in my directory
expect when the parent folder is named 'Views'

Ex directory:


-Web.config (should exclude)
-SomeOther.file (should allow)
-SubFolder (should allow)
-one.file (should allow)
-two.file (should allow)
-Web.config (should exclude)
-Web.config (should allow)

I have tried via the below in the .gitignore file, but doesnt seem to be working. The Web.config in the Views folder is not being added



Answer Source

It should be


**/[Ww]eb.config makes Git ignore files named Web.config and web.config in any folder, and !**/Views/[Ww]eb.config overrides previous pattern to not ignore these files if they are located within Views folder.

Also keep in mind that gitignore only works for currently untracked files:

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.

See How to make Git “forget” about a file that was tracked but is now in .gitignore?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download