2

I'm setting up my gitignore file and I want to ignore the Debug and Release directories that are created by Visual Studio's build process. But I have a Libraries folder than has sub folders for Debug and Release - I need these folders to be included.

The sub folders under Libraries are referenced in the projects using the build configuration so they need to include the Debug/Release names.

I tried using the ! command to negate the pattern, but this wasn't successful.

I'm looking for a .gitignore configuration that would enable me to include specifically the Libraries/Debug and Libraries/Release folders, but ignore all other Debug and Release folders.

Matthew van Boheemen
  • 1,087
  • 3
  • 13
  • 21
  • 1
    Please have a look at this link `https://stackoverflow.com/questions/2545602/git-ignore-sub-folders` and see if it helps – Swadhikar Feb 05 '19 at 05:05
  • Where are the `other Debug and Release folders` that needs to be ignored? Can you create a directory structure of your folders in your question? – sparsh Feb 05 '19 at 05:52

1 Answers1

4

To solve your problem, you need to put the more general rule first, to ignore all Debug and Release folders, and follow it by specific rules to not ignore the instances you want to track:

Release/*
Debug/*
!/Libraries/Release/*
!/Libraries/Debug/*

The important thing to know is that the contents of .gitignore are processed sequentially, with later lines overriding what was specified in earlier ones. So Release and Debug say ignore all instances of files or folders called that, but !/Libraries/Release says to not ignore Release found at specific path from the root of the repo.

If you reversed the order of these lines, it would not work as you want; this is a frequent gotcha when trying to use ! in .gitignore.

Edit: Added /* to each line to affect only folders with the given names, not regular files.

joanis
  • 10,635
  • 14
  • 30
  • 40
  • @MatthewvanBoheemen Curious minds want to know... did this work for you? – joanis Feb 07 '19 at 15:31
  • 1
    It did, but I needed to include /* on the folder to be ignored, e.g. Release/* – Matthew van Boheemen Feb 08 '19 at 04:21
  • It worked with and without the /* for me, but I guess the difference is that a regular file called Release would not be affected when you add the /*. I just added it to my answer, to make it match what worked for you, for the sake of future readers. Thanks for the feedback! – joanis Feb 08 '19 at 15:50