I have data directory in project's root. It has images directory and some files. Here is example:
data ├── images │ ├── image1.jpg │ ├── image2.jpg │ └── image3.jpg ├── results.csv └── r.txt
What to write in gitignore, to ignore files from data/ directory (that is results.csv and r.txt) and files from images/ directory (image.jpg, image2.jpg, image3.jpg)?
When I commit it, folder structure in repository should be:
data/ └── images/
So, I just want empty folder structure to be commited.
Yes, indeed, by design, you can not commit empty directories, containing no files, to a Git repository.
Since Git won't track empty directories, you have to trick it into doing so by adding a file in the directory to Git's index. Usually, people store a file called . gitkeep in a directory that they wish to track, but where the directory should stay empty for the time being.
Git doesn't ignore empty directories. It ignores all directories. In Git, directories exist only implicitly, through their contents. Empty directories have no contents, therefore they don't exist.
Just add a file .gitkeep
in every folder you want committed.
On windows do so by right clicking when in the folder and select: Git bash from here. Then type: touch .gitkeep
In Git, you cannot commit empty folders, because Git does not actually save folders, only files. You'll have to create some placeholder file inside those directories if you actually want them to be "empty" (i.e. you have no committable content).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With