How do I commit a folder but not its contents in PyCharm?

Viewed 33

I have a project checked out from GitHub and developing it in PyCharm. In summary, the application is a backend stack for a web application. There is an "uploads" folder where images uploaded from the frontend is saved. During development, data is saved into this folder. I've noticed that if I try to add the folder, its contents will also be added, but I don't want that — those are test data for the local development environment only, and should not be pushed into the repository. But if I don't add, then the folder will not be created in the repository but it needs to be deployed into production as an empty, existing folder. How can I commit just the folder and ignore anything that's added inside? I can't delete the contents before every commit, as the data correspond with database entries generated after some time-consuming machine learning work. It'll take easily 15-30 minutes in the backend to rebuild the dataset from scratch, never mind the file uploads from the frontend.

1 Answers

Git doesn't store directories that don't contain files; it doesn't support that. If you'd like the directory to be created, you have some options:

  • Add a deployment script that creates it. This could be a post-checkout or post-receive hook, depending on how you get the code onto the server.
  • Create some file in the directory, such as an empty .gitignore file, to ensure it gets created.
  • Use a deployment tool. Since Git is not a deployment tool, using a real deployment tool (such as Capistrano) can solve this problem for you.
Related