Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't git version directories?

Tags:

git

I'm well aware that git doesn't work on empty directories (one of the more popular git questions here), but I'm asking if there's a particular justification or rationale (official if possible) in not tracking directories.

I'm asking because directories, in some cases, can have meaningful metadata by themselves. For example, the file mode of a directory can be important if sticky modes are being used. The mere fact that a directory is empty may be important for an application.

like image 642
nneonneo Avatar asked Nov 27 '12 18:11

nneonneo


2 Answers

There is no official rationale. The Git FAQ simply states:

nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it

like image 57
Lyn Headley Avatar answered Sep 30 '22 06:09

Lyn Headley


Git tracks content, folders/directories are not content. Although you are right some metadata could be interesting for you. In such a case it's recommended to add a .gitignore file or some other meaningless file to the directory in order to provide a content that git will recognise.

See How can I add an empty directory to a Git repository?

It's just the way Git was designed to work.

In some web projects I used to do I needed a log directory for my php which was of course also ignoring the .log files, so in essence I had an empty log directory which was required for Apache to run correctly due to my vhost settings.

In this case I added a readme.txt with nothing inside.

I'm sure you've already come across this answer on the other thread, still worth a link: https://stackoverflow.com/a/115992/662605

like image 37
Daniel Avatar answered Sep 30 '22 07:09

Daniel