How to Add Empty Directory Structure to SVN Repository Without Files


2 views

Subversion (SVN) has a well-known behavior where it doesn't track empty directories by default. When you run svn add on a directory structure, it automatically includes all files within it. This becomes problematic when you need to commit just the folder structure without its contents.

Here are three reliable methods to solve this problem:

Method 1: Using .svn placeholder files

The most common approach is to create empty .svnkeep or .keep files in each directory:

mkdir -p project/{src,docs,config}
touch project/{src,docs,config}/.svnkeep
svn add project
svn commit -m "Added directory structure"

Method 2: SVN 1.7+ with --depth=empty

For newer SVN versions (1.7+), you can use the depth flag:

svn add --depth=empty directory_name
svn commit -m "Added empty directory structure"

Method 3: Scripted Solution for Complex Structures

For complex directory trees, use this bash script:

#!/bin/bash
find . -type d -not -path "*/.svn*" -print0 | xargs -0 -I {} svn add --depth=empty "{}"
svn commit -m "Added complete empty directory structure"

Empty directory structures are often needed for:

  • Initial project scaffolding
  • CI/CD pipeline requirements
  • Documentation of expected file locations
  • Team collaboration standards

If directories already contain files you want to exclude:

svn add --depth=empty existing_dir
svn propset svn:ignore "*" existing_dir
svn commit -m "Added dir while ignoring existing files"

For large repositories, consider sparse checkouts instead:

svn checkout --depth=immediates URL

This checks out only the top-level directories without their contents.


Version control systems typically ignore empty directories by design. When working with Subversion (SVN), you'll find that svn add commands don't persist empty folders in the repository. This becomes problematic when you need to maintain a specific directory structure without committing actual file content.

Here are three reliable methods to solve this:

Method 1: Using .svn placeholder files

mkdir -p project/{src,docs,config}
find project -type d -exec touch {}/.svnkeep \;
svn add project --force
svn commit -m "Added directory structure with placeholder files"

Method 2: The --depth empty flag

svn mkdir --parents trunk/branches/tags --depth empty
svn commit -m "Created empty SVN directory structure"

Method 3: Batch script approach

@echo off
for /d /r %%i in (*) do (
    svn add "%%i" --depth empty
)
svn commit -m "Added empty directory tree structure"
  • Preparing project scaffolding for team collaboration
  • Maintaining standardized directory layouts in large organizations
  • Creating template repositories with required subfolder hierarchy
Method Pros Cons
Placeholder files Works across all SVN versions Creates dummy files
--depth empty Clean solution Requires SVN 1.5+
Batch script Automates process Windows-only syntax

When working with CI/CD pipelines:

# Jenkins pipeline example
stage('Setup directories') {
    steps {
        bat 'svn mkdir --parents build/dist --depth empty'
        bat 'svn commit -m "CI: Created deployment directories"'
    }
}

If directories disappear after commit:

  1. Verify SVN version (svn --version)
  2. Check server-side hooks aren't modifying structure
  3. Confirm you're using proper depth parameters