0

I have a .gitignore file, which contains those 2 lines:

(1) [Bb]in/
(2) !X/Y/[Bb]in

My understanding is that is that the first line is a blanket statement saying that no files from Bin/bin folders should be included. The second line's intention is to implement an exception, namely to include all files in the Bin/bin folder of X/Y.

For some reason, content of X/Y/[Bb]in is still not included. I have to mainly use Visual Studio 2013 for git tfs but I also tried to force an inclusion via git bash using:

git add .

Is there something from with line (2)?

cs0815
  • 16,751
  • 45
  • 136
  • 299
  • You should not put binaries in a Git repository. Git cannot effectively version binaries and it will cause the repository to become extremely large over time. – Daniel Mann Mar 08 '16 at 13:37
  • I know this is bad practice but is necessary in this case. – cs0815 Mar 08 '16 at 13:45
  • It's definitely not necessary. You can use a package manager for your binary dependencies. A NuGet repo can be as simple as a folder on a file share. – Daniel Mann Mar 08 '16 at 13:52
  • 1
    I need it for automatic deploy to Azure: https://azure.microsoft.com/en-gb/documentation/articles/cloud-services-dotnet-install-dotnet/ Let's not get into more 'arguments' like this. Let's just pretend I talk about .txt files (-: – cs0815 Mar 08 '16 at 13:56

1 Answers1

2

The first line excludes the directory - wherever it is, and thus completely ignores whatever inside that directory, so you can't even re-include it. That is why your pattern doesn't work.

In order to make this work, you must exclude the files and folders, before you can re-include them. To make it a bit simpler, just assume one level ( removing the y-level) (I also skipped the uppercase/lowercase for clarity)

**/bin/**
x/**
!x/bin

This pattern will do exactly as you state above.
The first line excludes all content under any bin folder. The prefix ** makes it apply to any folder level, without it - it would only apply to the root level bin folder. The suffix ** makes it apply to the files and folder beneath it. The second line explicitly excludes the 'x' folder and its content. Yes, this is weird, but is what makes this work. Then the third line then re-includes the binary folder.

I assume you have some source code you want included under 'x', you then have the explicitly re-include that too, so good idea to place that under a separate folder.

See these posts for some of the same issues
Using .gitignore to ignore everything but specific directories
What's the difference between Git ignoring directory and directory/*?
.gitignore exclude folder but include specific subfolder

Community
  • 1
  • 1
Terje Sandstrøm
  • 1,979
  • 15
  • 14