git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] Storing empty directories in Git

From
Øyvind A. Holm <sunny@sunbase.org>
Date
May 30, 2010, 14:29 UTC
Message-ID
<20100530142908.GA7180@triton>

I sometimes need to store empty directories in Git, and instead of putting empty .gitignore files everywhere as has been suggested, I created two small shell scripts (git-store-dirs and git-restore-dirs) to store all empty directories in a file named ".emptydirs" at the top of the working tree. The directories are stored as null-separated strings to avoid problems with wacky things like \n or semicolons in the directory names.

Is this a viable method of fixing the emptydir problem? A default file name like ".gitdirectories" could be used, or maybe it’s possible to store a file like this inside the .git/ area if we can come up with a way to store this metadata properly.

The scripts are stored at http://gist.github.com/419015 , but I also include them here:

### git-store-dirs {{{
#!/bin/sh

# git-store-dirs # Store a list of all directories to $dirfile to be able to restore empty # directories. The list is \0-separated in case there are some directory names # containing (ugh) \n. Use git-restore-dirs(1) to recreate directories.

dirfile=.emptydirs test -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; } find -type d -empty -print0 | grep -E -v -z '/\.git(/|$)' | LC_ALL=C sort -z >$dirfile git add $dirfile

### }}} ### git-restore-dirs {{{

#!/bin/sh

# git-restore-dirs # Restore empty directories created by git-store-dirs(1)

dirfile=.emptydirs test -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; } test -e $dirfile || { echo $0: No $dirfile file found >&2; exit 1; } xargs -0 mkdir -p <$dirfile

### }}}

Cheers, Øyvind

+-| Øyvind A. Holm <sunny@sunbase.org> - N 60.39548° E 5.31735° |-+
| OpenPGP: 0xFB0CBEE894A506E5 - http://www.sunbase.org/pubkey.asc |
| Fingerprint: A006 05D6 E676 B319 55E2  E77E FB0C BEE8 94A5 06E5 |
+------------| 06a9d9be-6bf2-11df-8623-90e6ba3022ac |-------------+
Message 1 of 1 in “[RFC] Storing empty directories in Git”
  1. Øyvind A. HolmMay 30, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.