How do I “externalize” a file using SVN?

December 6, 2010 in Recipes, Subversion by Marco Zuliani

This is the problem. Suppose you have a directory Paper under revision control and suppose you need to have inside this directory a file (call this file foo.bib for example) that is located in somewhere else in the repository (e.g. /Volumes/Storage/SVNRepository/Bibliography/).

The idea is that when you do an update the file foo.bib is fetched from the right repository. Similarly when you do a commit the modifications to foo.bib are sent to the right repository.

The solution is to “externalize” the file foo.txt. To do this issue the following command from inside the directory Paper:

svn propset svn:externals 'foo.bib file://localhost/Volumes/Storage/SVNRepository/Bibliography/foo.bib' .

where the end dot matters. SVN will respond saying property 'svn:externals' set on '.'

Do not forget to commit the changes with:

svn commit -m "externals"

To verify that the file is externalized type:

svn status foo.txt

The file is hopefully labelled as X.

What if we want to externalize more than one file? In this case it is a good idea to create a ASCII file containing the list of files and their links to the repository. For example edit the file externals.txt as:

foo1.bib file://localhost/Volumes/Storage/SVNRepository/Bibliography/foo1.bib
foo2.bib file://localhost/Volumes/Storage/SVNRepository/Bibliography/foo2.bib

Once the file is saved (you may even want to add it to your repository for future use…) enter the command:

svn propset svn:externals -F externals.txt .

Also in this case do not forget to commit. In case you screwed up something, just overwrite the property and commit again.

This approach works similarly if you want to externalize directories.

Check the beer planet blog for a more thorough discussion and some other useful links.