Checkout one file from Subversion
“It is not possible to check out a single file. The finest level of checkouts you can do is at the directory level.”
How do I get around this issue when using Subversion?
We have this folder in Subversion where we keep all our images. I just want to check out one file (image) from that. This folder is really big and has ton of other stuff which I don’t need now.
19 Solutions collect form web for “Checkout one file from Subversion”
The simple answer is that you
svn export the file instead of checking it out.
But that might not be what you want. You might want to work on the file and check it back in, without having to download GB of junk you don’t need.
If you have Subversion 1.5+, then do a sparse checkout:
svn checkout <url_of_big_dir> <target> --depth empty cd <target> svn up <file_you_want>
For an older version of SVN, you might benefit from the following:
- Checkout the directory using a revision back in the distant past, when it was less full of junk you don’t need.
- Update the file you want, to create a mixed revision. This works even if the file didn’t exist in the revision you checked out.
An alternative (for instance if the directory has too much junk right from the revision in which it was created) is to do a URL->URL copy of the file you want into a new place in the repository (effectively this is a working branch of the file). Check out that directory and do your modifications.
I’m not sure whether you can then merge your modified copy back entirely in the repository without a working copy of the target – I’ve never needed to. If so then do that.
If not then unfortunately you may have to find someone else who does have the whole directory checked out and get them to do it. Or maybe by the time you’ve made your modifications, the rest of it will have finished downloading…
svn export instead of
svn checkout. That works for single files.
The reason for the limitation is that
checkout creates a working copy, that contains meta-information about repository, revision, attributes, etc. That metadata is stored in subdirectories named ‘.svn’. And single files don’t have subdirectories.
svn cat or
For that, you don’t need to fetch the working directory, but you will not be able to commit any changes you make. If you need to make changes and commit them, you need a working directory, but you don’t have to fetch it completely. Checkout the revision where the directory was still/almost empty, and then use ‘svn cat’ to extract the file from HEAD.
If you want to view readme.txt in your
repository without checking it out:
$ svn cat
This is a README file. You should read
If your working copy is out of date
(or you have local modifications) and
you want to see the HEAD revision of a
file in your working copy, svn cat
will automatically fetch the HEAD
revision when you give it a path:
$ cat foo.c
This file is in my local
working copy and has changes that
$ svn cat foo.c
Latest revision fresh
from the repository!
A TortoiseSVN equivalent solution of the accepted answer (I had written this in an internal document for my company as we are newly adopting SVN) follows. I thought it would be helpful to share here as well:
Checking out a single file:
Subversion does not support checkout of a single file, it only supports checkout of directory structures. (Reference: http://subversion.tigris.org/faq.html#single-file-checkout). This is because with every directory that is checked out as a working copy, the metadata regarding modifications/file revisions is stored as an internal hidden folder (.svn/_svn). This is not supported currently (v1.6) for single files.
Alternate recommended strategy: You will have to do the checkout directory part only once, following that you can directly go and checkout your single files. Do a sparse checkout of the parent folder and directory structure. A sparse checkout is basically checking out only the folder structure without populating the content files. So you checkout only the directory structures and need not checkout ALL the files as was the concern.
Step 1: Proceed to repository browser
Step 2: Right click the parent folder within the repository containing all the files that you wish to work on and Select Checkout.
Step 3: Within new popup window, ensure that the checkout directory points to the correct location on your local PC. There will also be a dropdown menu labeled “checkout depth”. Choose “Only this item” or “Immediate children, including folders” depending on your requirement. Second option is recommended as, if you want to work on nested folder, you can directly proceed the next time otherwise you will have to follow this whole procedure again for the nested folder.
Step 4: The parent folder(s) should now be available within your locally chosen folder and is now being monitored with SVN (a hidden folder “.svn” or “_svn” should now be present). Within the repository now, right click the single file that you wish to have checked out alone and select the “Update Item to revision” option. The single file can now be worked on and checked back into the repository.
I hope this helps.
An update in case what you really need can be covered by having the file included in a checkout of another folder.
Since SVN 1.6 you can make file externals, a kind of svn links. It means that you can have another versioned folder that includes a single file. Committing changes to the file in a checkout of this folder is also possible.
It’s very simple, checkout the folder you want to include the file, and simply add a property to the folder
svn propedit svn:externals .
with content like this:
After you commit this, the file will appear in future checkouts of the folder. Basically it works, but there are some limitations as described in the documentation linked above.
You can do it in two steps:
Checkout an empty SVN repository with meta information only:
$ cd /tmp $ svn co --depth empty http://svn.your.company.ca/training/trunk/sql
svn upto update specified file:
$ svn up http://svn.your.company.ca/training/trunk/sql/showSID.sql
Go to the repo-browser right-click the file and use ‘Save As’, I’m using TortoiseSVN though.
Steve Jessop’s answer did not work for me. I read the help files for SVN and if you just have an image you probably don’t want to check it in again unless you’re doing Photoshop, so export is a better command than checkout as it’s unversioned (but that is minor).
And the –depth ARG should not be empty but files to get the files in the immediate directory. So you’ll get all the fields, not just the one, but empty returns nothing from the repository.
svn co --depth files <source> <local dest>
svn export --depth files <source> <local dest>
As for the other answers, cat lets you read the content which is good only for text, not images of all things.
I’d just browse it and export the single file. If you have HTTP access, just use the web browser to find the file and grab it.
If you need to get it back in after editing it, that might be slightly more tedious, but I’m sure there might be an
svn import function…
cd C:\path\dir svn checkout https://server/path/to/trunk/dir/dir/parent_dir--depth empty cd C:\path\dir\parent_dir svn update filename.log
svn commit -m "this is a comment."
If you just want a file without revision information use
svn export <URL>
With Subversion 1.5, it becomes possible to check out (all) the files of a directory without checking out any subdirectories (the various –depth flags). Not quite what you asked for, but a form of “less than all.”
If you just want to export the file, and you won’t need to update it later, you can do it without having to use SVN commands.
Using TortoiseSVN Repository Browser, select the file, right click, and then select “Copy URL to clipboard“. Paste that URL to your browser, and after login you should be prompted with the file download.
This way you can also select desired revision and download an older version of the file.
Note that this is valid if your SVN server has a web interface.
Using the sparse check out technique, you CAN check out a particular file that is already checked out or exists…with a simple trick:
After checkout of the top level of your repository using the ‘this item only’ option, in Windows explorer, you MUST first right-click on the file you need to update; choose Repo Browser in context menu; find that file AGAIN in repository browser, and right-click. You should now see the “update item to revision” in context menu.
I’m not sure whether it is an undocumented feature or simply a bug. It took me an extended after-work hours to finally find this trick. I’m using TortoiseSVN 1.6.2.
I wanted to checkout a single file to a directory, which was not part of a working copy.
Let’s get the file at the following URL: http://subversion.repository.server/repository/module/directory/myfile
svn co http://subversion.repository.server/repository/module/directory/myfile /**directoryb**
So I checked out the given directory containing the target file I wanted to get to a dummy directory, (say etcb for the URL ending with
Then I emptied the file .svn/entries from all files of the target directory I didn’t needed, to leave just the file I wanted. In this .svn/entries file, you have a record for each file with its attributes so leave just the record concerning the file you want to get and save.
Now you need just to copy then ”.svn” to the directory which will be a new “working copy”. Then you just need to:
cp .svn /directory cd /directory svn update myfile
Now the directory directory is under version control. Do not forget to remove the directory directoryb which was just a ”temporary working copy”.
Do something like this:
mkdir <your directory>/repos/test svn cat http://svn.red-bean.com/repos/test/readme.txt > <your directory>/repos/test/readme.txt
Basically the idea is create the directory where you want to grab the file from SVN.
svn cat command and redirect the output to the same named file. By default, the cat will dump information on stdio.
This issue is covered by:
There is a script attached that lets you check out a single file from svn, make changes, and commit the changes back to the repository, but you can’t run “svn up” to checkout the rest of the directory. It’s been tested with svn-1.3, 1.4 and 1.6.
Since none of the other answers worked for me I did it using this hack:
$ cd /yourfolder svn co https://path-to-folder-which-has-your-files/ --depth files
This will create a new local folder which has only the files from the remote path.
Then you can do a symbolic link to the files you want to have here.