Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we set a single file as external in Subversion?

People also ask

What is an external in svn?

An externals definition is a mapping of a local directory to the URL—and ideally a particular revision—of a versioned directory. In Subversion, you declare externals definitions in groups using the svn:externals property.

How do I view svn externals?

If you need to see all svn:externals in a directory structure, this is your huckleberry: svn propget -R svn:externals . Logging this here for my own future reference.

What does svn copy do?

svn copy (cp) — Copy a file or directory in a working copy or in the repository.


Yes, it's possible with svn 1.6. It's documented in the nightly build version of the svn book.

But even though file externals are working, you should only do it with text files (for now) because binary files won't work correctly as file externals.


As mentioned in the first answer, SVN Externals are documented in Chapter 3 of the SVN Book, and quite a few syntax examples are given there.

In addition, this note is given:

"Because the svn:externals property has a multiline value, we strongly recommend that you use svn propedit instead of svn propset."

In my experience testing Tortoise SVN v1.9.6 and svn.exe v1.9.5, the results are as-documented.

  • Bringing in an external folder with all its files works.
  • Bringing in a single file from the same repo works.
  • Bringing in a single file from a different repo fails and this limitation is documented in the SVN book.

This leads to a clumsy workaround. If you control both repos, you can clone an individual file into its own folder in the source repo (by Externals of a single file WITHIN a repo), and then Externals it across repo borders into the target repo by bringing in its entire folder, which contains only a single file.

Docs for doing this with the Tortoise SVN client are on tortoisesvn.net.


I couldn't find a good example about how to create a svn file external. So I am providing an example here so it can be useful for others.

The format is

svn propset svn:externals "<local file> <remote svn file>" <local dir>

For e.g. following command

svn propset svn:externals "my.cfg https://myserver/my/svn/location/my_sample_file.cfg.template" my_folder

will create the file https://myserver/my/svn/location/my_sample_file.cfg.template under my_folder as my.cfg. Here obviously, I assume you already have the folder my_folder under your current directory which is under svn.


For SVN 1.9.4 the syntax is like folder's one:

svn propset svn:externals <remote file> <local file>

E.g., this will create file local.txt in the current directory referencing to file.txt:

svn propset svn:externals ^/trunk/path/to/file.txt local.txt