Adding Empty Directories to git-svn

Just a reminder, because I always forget it: When you use git-svn on an svn repository and your code base contains empty directories (say, for temporary files, or log files), they will be ignored by git unless they contain at least one file.

Paradox? Maybe. There’s a good reason however: git ignores empty directories because it tracks (file) content, not a bunch of directories some of which happen to contain a file (the concept of tracking files might be the only thing git has remotely in common with good ol’ CVS — though git also does not deeply care about file names, only content).

The “common” way to handle this is by adding a .gitignore file to the repository. This won’t harm svn-only clients, but it’ll make git-svn clients pick up the (almost) empty directory properly.

This is what you need to do.

mkdir empty_dir
echo '*' > empty_dir/.gitignore
echo '!.gitignore' >> empty_dir/.gitignore
git add empty_dir
git commit -m 'adding empty directory' empty_dir

The .gitignore file tells git what file names not to track inside the directory in question. The asterisk means, ignore all files, but the second line makes sure the .gitignore file itself is recognized and added to the repository.



3 Responses to “Adding Empty Directories to git-svn”

  1. Feels good, doesn’t it?

  2. About as good as hitting your thumb with a huge hammer ;)

  3. Hi, I wrote an open source tool MarkEmptyDirs which is able to create and delete such files automatically. It scans a directory tree for empty directories and creates such placeholder files. You can configure the content of such files using a template and template variables. If later on placeholder files become unnecessary (because “empty” directories now contain “real” files or subdirectories, the placeholder files are removed again. It is even possible to hook into placeholder file creation/deletion and automatically invoke git in order to add/remove the placeholder files from the repository.

    Best regards and have fun with it :)

    Jonny Dee

Leave a Reply