Keep git-svn from keeping empty directories

git-svn keeps empty directories, which may become a problem (e.g.) when renaming directories. This behavior manifests in messages such as “W: -empty_dir abc/dir” during dcommit and, how it can be altered, I describe in this article.

Configuration for removing empty directories during git svn dcommit

To avoid keeping empty directories around, use the –rmdir flag during git svn dcommit:

To make this behavior permanent, we can use git config (Can be verified by taking a look at the [svn] section in ~/.gitconfig):

Now, when performing svn dcommit, you should see that empty directories get deleted (see the lines starting with D+).

Removing legacy empty directories

For the time being, we only fixed the future behavior of git svn, but there are still empty directories left in the Subversion repository. To clean these up, we need an Subversion working copy of the repository. Go to the SVN working copy and determine the empty directories:

This call will exclude the .svn directory (-prune flag) and include the “lowest” empty directories in the directory tree. Therefore, we need to iterate the deletion procedure several times until no more empty “leaf directories” remain. Next, investigate empty_dirs.txt and see whether it contains directories that you want to keep – edit empty_dirs.txt if necessary:

Now comes the time to schedule the directories for deletion (if there remain empty directories to be deleted):

Now, rerun the find command to find directories that are now eligible for deletion and repeat the xargs svn delete. At the end, review you changes with svn status and commit them with

Finally, the same steps have to be performed in the git svn working copy after a git svn rebase.


  • [1] Peter Boling describes a similar solution