# Handling empty directories in Git

9 messages from 2014-04-08 to 2014-04-11. Participants: Olivier LE ROY, Andrew Keller, Matthieu Moy, David Kastrup, Øyvind A. Holm.
Thread: https://gitlist.dev/t/36369

## Olivier LE ROY, 2014-04-08 14:47

Subject: Handling empty directories in Git
Message-ID: <1396968442.95061.YahooMailNeo@web120806.mail.ne1.yahoo.com>
URL: https://gitlist.dev/e/1396968442.95061.YahooMailNeo%40web120806.mail.ne1.yahoo.com

```
Hello, 

I have a project under SVN with contains empty directories.

I would like to move this project on a Git server, still handling empty directories.

The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.

Is there any expert able to tell me: this cannot be done in Git, or this can be done by the following trick, or why there is no valuable reason to maintain empty directories under version control?

Regards,

Olivier LE ROY
France

```

## Andrew Keller, 2014-04-08 17:02

Subject: Re: Handling empty directories in Git
Message-ID: <3FBDE5D3-1DC6-420C-866B-036D0CB17BA2@kellerfarm.com>
URL: https://gitlist.dev/e/3FBDE5D3-1DC6-420C-866B-036D0CB17BA2%40kellerfarm.com
In-Reply-To: <1396968442.95061.YahooMailNeo@web120806.mail.ne1.yahoo.com>

```
On Apr 8, 2014, at 10:47 AM, Olivier LE ROY <olivier_le_roy@yahoo.com> wrote:

> Hello, 
> 
> I have a project under SVN with contains empty directories.
> 
> I would like to move this project on a Git server, still handling empty directories.
> 
> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.
> 
> Is there any expert able to tell me: this cannot be done in Git, or this can be done by the following trick, or why there is no valuable reason to maintain empty directories under version control?

Git is designed to track files.  The existence of folders is secondary to the notion that files have a relative path inside the repository, which is perceived by the user as folders.

Why can't your scripts create the folders on demand?  Or, could your scripts interpret a missing folder as an empty folder?

Thanks,
Andrew Keller

```

## Matthieu Moy, 2014-04-08 17:03

Subject: Re: Handling empty directories in Git
Message-ID: <vpqob0blpna.fsf@anie.imag.fr>
URL: https://gitlist.dev/e/vpqob0blpna.fsf%40anie.imag.fr
In-Reply-To: <1396968442.95061.YahooMailNeo@web120806.mail.ne1.yahoo.com>

```
Olivier LE ROY <olivier_le_roy@yahoo.com> writes:

> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.

Another option is to have a post-checkout hook that does the mkdir for
you. Or do that in the build system if your use case is to store
untracked generated files in the directory.

> Is there any expert able to tell me: this cannot be done in Git, or
> this can be done by the following trick,

https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F

Short answer: it cannot be done.

> or why there is no valuable reason to maintain empty directories under
> version control?

The reason would be closer to "there is a valuable reason, but not
valuable enough to change Git to do it". It's actually not so easy to
track directories properly. Storing them in the Git repository is
actually possible (actually, an empty tree is a special case of this,
and is obviously supported), but defining and implementing a decent
behavior for each Git command wrt this is not trivial.

David Kastrup gave it a try a few years ago. I don't remember exactly
what made him give up, but it was never completed and merged.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Andrew Keller, 2014-04-08 17:20

Subject: Re: Handling empty directories in Git
Message-ID: <AE92C2A5-4EFE-454C-8D61-804AEE72D955@kellerfarm.com>
URL: https://gitlist.dev/e/AE92C2A5-4EFE-454C-8D61-804AEE72D955%40kellerfarm.com
In-Reply-To: <3FBDE5D3-1DC6-420C-866B-036D0CB17BA2@kellerfarm.com>

```
On Apr 8, 2014, at 1:02 PM, Andrew Keller <andrew@kellerfarm.com> wrote:

> On Apr 8, 2014, at 10:47 AM, Olivier LE ROY <olivier_le_roy@yahoo.com> wrote:
> 
>> Hello, 
>> 
>> I have a project under SVN with contains empty directories.
>> 
>> I would like to move this project on a Git server, still handling empty directories.
>> 
>> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.
>> 
>> Is there any expert able to tell me: this cannot be done in Git, or this can be done by the following trick, or why there is no valuable reason to maintain empty directories under version control?
> 
> Git is designed to track files.  The existence of folders is secondary to the notion that files have a relative path inside the repository, which is perceived by the user as folders.

To clarify: That's Git's "personality" from the point of view of the front end, and is not the same as how data is actually stored.

Thanks,
Andrew Keller

```

## David Kastrup, 2014-04-08 17:36

Subject: Re: Handling empty directories in Git
Message-ID: <87zjjvg1v1.fsf@fencepost.gnu.org>
URL: https://gitlist.dev/e/87zjjvg1v1.fsf%40fencepost.gnu.org
In-Reply-To: <vpqob0blpna.fsf@anie.imag.fr>

```
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> The reason would be closer to "there is a valuable reason, but not
> valuable enough to change Git to do it". It's actually not so easy to
> track directories properly. Storing them in the Git repository is
> actually possible (actually, an empty tree is a special case of this,
> and is obviously supported), but defining and implementing a decent
> behavior for each Git command wrt this is not trivial.
>
> David Kastrup gave it a try a few years ago. I don't remember exactly
> what made him give up, but it was never completed and merged.

Oh, most likely what afflicts most of my unfinished projects.  I lost
focus at some point of time.  I don't remember any fundamentally
unsolvable problems, but then I don't remember much at all.  There were
some annoyances with sorting order (either regarding the sorting of xxx/
or . or ./ or whatever) and some other stuff.

If anybody wants to take a look at the direction of unfinished stuff,
I can see whether there are some old backups with git repos in my
possession.  But I really have no idea how much of the design might have
ended up in actual comments or code, and how much on some scraps of
paper or half-committed memory, and how much of that might have been
invalidated by other scraps of paper and half-committed memory.

So there is not likely to be more than food for thought recoverable.

I'm amused that you remember me being involved with that.  I think
I myself had forgotten all about it until recently.  I don't even
recollect what made me remember again: looking at some old repo/commit
or searching in some old mailing list archive.

-- 
David Kastrup

```

## Olivier LE ROY, 2014-04-08 17:47

Subject: Re: Handling empty directories in Git
Message-ID: <1396979249.39960.YahooMailNeo@web120805.mail.ne1.yahoo.com>
URL: https://gitlist.dev/e/1396979249.39960.YahooMailNeo%40web120805.mail.ne1.yahoo.com
In-Reply-To: <3FBDE5D3-1DC6-420C-866B-036D0CB17BA2@kellerfarm.com>

```


Hello Andrew,

yes that is possible to have scripts create the missing directories.

The reason I asked this is people at my work want to avoid the hassle of having to create a script for that. They want to checkout seamlessly as they used to do with subversion.

I guess it is similar as programming in Java and programming in plain old C.


Olivier LE ROY 

________________________________
De : Andrew Keller <andrew@kellerfarm.com>
À : Olivier LE ROY <olivier_le_roy@yahoo.com> 
Cc : "git@vger.kernel.org" <git@vger.kernel.org> 
Envoyé le : Mardi 8 avril 2014 17h02
Objet : Re: Handling empty directories in Git


On Apr 8, 2014, at 10:47 AM, Olivier LE ROY <olivier_le_roy@yahoo.com> wrote:


> Hello, 
> 
> I have a project under SVN with contains empty directories.
> 
> I would like to move this project on a Git server, still handling empty directories.
> 
> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.
> 
> Is there any expert able to tell me: this cannot be done in Git, or this can be done by the following trick, or why there is no valuable reason to maintain empty directories under version control?

Git is designed to track files.  The existence of folders is secondary to the notion that files have a relative path inside the repository, which is perceived by the user as folders.

Why can't your scripts create the folders on demand?  Or, could your scripts interpret a missing folder as an empty folder?

Thanks,
Andrew Keller

```

## Olivier LE ROY, 2014-04-08 18:06

Subject: Re: Handling empty directories in Git
Message-ID: <1396980369.49724.YahooMailNeo@web120801.mail.ne1.yahoo.com>
URL: https://gitlist.dev/e/1396980369.49724.YahooMailNeo%40web120801.mail.ne1.yahoo.com
In-Reply-To: <vpqob0blpna.fsf@anie.imag.fr>

```
Hi Mattieu,

thanks for this answer. It is clear enough.

Olivier LE ROY




----- Mail original -----
De : Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
À : Olivier LE ROY <olivier_le_roy@yahoo.com>
Cc : "git@vger.kernel.org" <git@vger.kernel.org>
Envoyé le : Mardi 8 avril 2014 17h03
Objet : Re: Handling empty directories in Git

Olivier LE ROY <olivier_le_roy@yahoo.com> writes:

> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.

Another option is to have a post-checkout hook that does the mkdir for
you. Or do that in the build system if your use case is to store
untracked generated files in the directory.

> Is there any expert able to tell me: this cannot be done in Git, or
> this can be done by the following trick,

https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F

Short answer: it cannot be done.


> or why there is no valuable reason to maintain empty directories under
> version control?

The reason would be closer to "there is a valuable reason, but not
valuable enough to change Git to do it". It's actually not so easy to
track directories properly. Storing them in the Git repository is
actually possible (actually, an empty tree is a special case of this,
and is obviously supported), but defining and implementing a decent
behavior for each Git command wrt this is not trivial.

David Kastrup gave it a try a few years ago. I don't remember exactly
what made him give up, but it was never completed and merged.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Olivier LE ROY, 2014-04-08 18:39

Subject: Re: Handling empty directories in Git
Message-ID: <1396982365.73812.YahooMailNeo@web120805.mail.ne1.yahoo.com>
URL: https://gitlist.dev/e/1396982365.73812.YahooMailNeo%40web120805.mail.ne1.yahoo.com
In-Reply-To: <87zjjvg1v1.fsf@fencepost.gnu.org>

```
Hi David,

thanks for the whole story. We understand why the empty directories handling was never completed, and how it could be, if one developer submited patches for that.

Regards,

Olivier LE ROY



----- Mail original -----
De : David Kastrup <dak@gnu.org>
À : Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc : Olivier LE ROY <olivier_le_roy@yahoo.com>; "git@vger.kernel.org" <git@vger.kernel.org>
Envoyé le : Mardi 8 avril 2014 17h36
Objet : Re: Handling empty directories in Git

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

> The reason would be closer to "there is a valuable reason, but not
> valuable enough to change Git to do it". It's actually not so easy to
> track directories properly. Storing them in the Git repository is
> actually possible (actually, an empty tree is a special case of this,
> and is obviously supported), but defining and implementing a decent
> behavior for each Git command wrt this is not trivial.
>
> David Kastrup gave it a try a few years ago. I don't remember exactly
> what made him give up, but it was never completed and merged.

Oh, most likely what afflicts most of my unfinished projects.  I lost
focus at some point of time.  I don't remember any fundamentally
unsolvable problems, but then I don't remember much at all.  There were
some annoyances with sorting order (either regarding the sorting of xxx/
or . or ./ or whatever) and some other stuff.

If anybody wants to take a look at the direction of unfinished stuff,
I can see whether there are some old backups with git repos in my
possession.  But I really have no idea how much of the design might have
ended up in actual comments or code, and how much on some scraps of
paper or half-committed memory, and how much of that might have been
invalidated by other scraps of paper and half-committed memory.

So there is not likely to be more than food for thought recoverable.

I'm amused that you remember me being involved with that.  I think
I myself had forgotten all about it until recently.  I don't even
recollect what made me remember again: looking at some old repo/commit
or searching in some old mailing list archive.


-- 
David Kastrup

```

## Øyvind A. Holm, 2014-04-11 12:34

Subject: Re: Handling empty directories in Git
Message-ID: <CAA787rmfWqjkBe0cT4-aXD0uPi-pWhjK0K0g2Vm8V0bJ7TLoMg@mail.gmail.com>
URL: https://gitlist.dev/e/CAA787rmfWqjkBe0cT4-aXD0uPi-pWhjK0K0g2Vm8V0bJ7TLoMg%40mail.gmail.com
In-Reply-To: <1396968442.95061.YahooMailNeo@web120806.mail.ne1.yahoo.com>

```
On 8 April 2014 16:47, Olivier LE ROY <olivier_le_roy@yahoo.com> wrote:
> Hello,
>
> I have a project under SVN with contains empty directories.
>
> I would like to move this project on a Git server, still handling empty directories.
>
> The solution: put a .gitignore file in each empty directory to have them recognized by the Git database cannot work, because some scripts in my projects test the actual emptiness of the directories.
>
> Is there any expert able to tell me: this cannot be done in Git, or this can be done by the following trick, or why there is no valuable reason to maintain empty directories under version control?

Git doesn't support storage of empty directories, but there are ways
around it. As you say, you could place empty files in every directory,
but I've never liked this concept. Instead, I use a couple of scripts
to store/restore empty directories:

https://gist.github.com/sunny256/419015

This creates a file called ".emptydirs" at the top of the repo, and it
can easily be implemented into scripts and build processes.

Greetings,
Øyvind

```
