-1

I ignore the folder "Debug" using .gitignore. But in "Debug" there is a folder "Docs" that I want to keep (also the files in there). So how do I have to configure .gitignore to only keep the folder "Docs" with its files but ignore all the rest of "Debug"?

3
  • Not sure that can be done with .gitignore alone, if I remember correctly, you cannot re-include files if you have excluded a parent directory. You can always just forcibly track the files, once tracked they will stay tracked, using git add -f path-to-file(s), but I'm not sure you can easily manage this. Why is the folder placed under Debug, and is this a .NET Project? If it is, then you should definitely not put files you want to keep inside the Debug folder. Commented Oct 12, 2018 at 8:14
  • Later those files will be in the ApplicationStartupPath. Yes, it is a .NET-project. Since "Debug" is the StartupPath at the moment, the files are kept there. Commented Oct 12, 2018 at 8:19
  • You should change your program so that you have a configuration somewhere that specifies where the documents can be found, it doesn't have to be configurable by the end user but could detect DEBUG vs. PRODUCTION and pick the right folder depending on that. This would allow you to place the folders, during debug and development, outside of the Debug folder. Commented Oct 12, 2018 at 8:21

1 Answer 1

1

It is very simple. Just follow these steps:

  1. Remove the entry of your debug folder from your .gitignore file.
  2. In the debug folder, create a new .gitignore file and write these two lines in it.

* !Docs

It will ignore everything in your debug folder except docs folder and its content.

Not the answer you're looking for? Browse other questions tagged or ask your own question.