2

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:

-Root

  -ApiProject
      -Web.config (should exclude)
      -SomeOther.file (should allow)
      -SubFolder     (should allow)
          -one.file     (should allow)
          -two.file     (should allow)
  -MvcProject
      -Web.config (should exclude)
      -Views
          -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

[Ww]eb.config

!**/Views/[Ww]eb.config

nadlie
  • 43
  • 7
  • What is not working? Is the file in "Views" also ignored? Or are the files in "MvcProject" and "ApiProject" not ignored? In the later case: Were those files committed before? Showing the result of `git status` might help to understand what is happening. – lucash Oct 19 '16 at 09:40
  • Its the Web.config in the Views folder which is not being added. – nadlie Oct 19 '16 at 10:00

1 Answers1

2

It should be

**/[Ww]eb.config
!**/Views/[Ww]eb.config

**/[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?

Community
  • 1
  • 1
Mykhailo
  • 1,134
  • 2
  • 17
  • 25
  • This is exactly it. I had just added this before i read your comment. And its working as expected. – nadlie Oct 19 '16 at 10:03