Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit empty folder structure (with git) [duplicate]

Tags:

git

gitignore

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.

like image 799
Иван Бишевац Avatar asked Jan 26 '13 20:01

Иван Бишевац


People also ask

Can you commit an empty folder in git?

Yes, indeed, by design, you can not commit empty directories, containing no files, to a Git repository.

Does git track empty folders?

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.

Why Git does not track empty folders?

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.


2 Answers

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

like image 176
Joost van der Laan Avatar answered Oct 14 '22 12:10

Joost van der Laan


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).

like image 29
Nevik Rehnel Avatar answered Oct 14 '22 14:10

Nevik Rehnel