<p>If I had 20 directories under trunk/ with lots of files in each and only needed 3 of those directories, would it be possible to do a Subversion checkout with only those 3 directories under trunk?</p>

[{'answer_id': 50953, 'author': 'zigdon', 'author_id': 4913, 'author_profile': 'https://Stackoverflow.com/users/4913', 'pm_score': 3, 'selected': False, 'text': '<p>Or do a non-recursive checkout of /trunk, then just do a manual update on the 3 directories you need.</p>\n'}, {'answer_id': 50955, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': -1, 'selected': False, 'text': "<p>Not in any especially useful way, no.  You can check out subtrees (as in Bobby Jack's suggestion), but then you lose the ability to update/commit them atomically; to do that, they need to be placed under their common parent, and as soon as you check out the common parent, you'll download everything under that parent.  Non-recursive isn't a good option, because you want updates and commits to be recursive.</p>\n"}, {'answer_id': 50956, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': -1, 'selected': False, 'text': "<p>Sort of.  As Bobby says:</p>\n\n<pre><code>svn co file:///.../trunk/foo file:///.../trunk/bar file:///.../trunk/hum\n</code></pre>\n\n<p>will get the folders, but you will get separate folders from a subversion perspective.  You will have to go separate commits and updates on each subfolder.</p>\n\n<p>I don't believe you can checkout a partial tree and then work with the partial tree as a single entity.</p>\n"}, {'answer_id': 50980, 'author': 'pkaeding', 'author_id': 4257, 'author_profile': 'https://Stackoverflow.com/users/4257', 'pm_score': 8, 'selected': False, 'text': '<p>Indeed, thanks to the comments to my post here, it looks like <a href="http://svnbook.red-bean.com/en/1.8/svn.advanced.sparsedirs.html" rel="noreferrer">sparse directories</a> are the way to go. I believe the following should do it:</p>\n\n<pre><code>svn checkout --depth empty http://svnserver/trunk/proj\nsvn update --set-depth infinity proj/foo\nsvn update --set-depth infinity proj/bar\nsvn update --set-depth infinity proj/baz\n</code></pre>\n\n<p>Alternatively, <code>--depth immediates</code> instead of <code>empty</code> checks out files and directories in <code>trunk/proj</code> without their contents. That way you can see which directories exist in the repository.</p>\n\n<hr>\n\n<p>As mentioned in @zigdon\'s answer, you can also do a non-recursive checkout. This is an older and less flexible way to achieve a similar effect:</p>\n\n<pre><code>svn checkout --non-recursive http://svnserver/trunk/proj\nsvn update trunk/foo\nsvn update trunk/bar\nsvn update trunk/baz\n</code></pre>\n'}, {'answer_id': 51031, 'author': 'Richard Morgan', 'author_id': 2258, 'author_profile': 'https://Stackoverflow.com/users/2258', 'pm_score': 7, 'selected': True, 'text': '<p>Subversion 1.5 introduces sparse checkouts which may be something you might find useful. From the <a href="http://svnbook.red-bean.com/en/1.8/svn.advanced.sparsedirs.html" rel="noreferrer">documentation</a>:</p>\n\n<blockquote>\n  <p>... <em>sparse directories</em> (or <em>shallow checkouts</em>) ... allows you to easily check out a working copy—or a portion of a working copy—more shallowly than full recursion, with the freedom to bring in previously ignored files and subdirectories at a later time.</p>\n</blockquote>\n'}, {'answer_id': 6686476, 'author': 'kostmo', 'author_id': 105137, 'author_profile': 'https://Stackoverflow.com/users/105137', 'pm_score': 3, 'selected': False, 'text': '<p>I wrote a script to automate complex sparse checkouts.</p>\n\n\n\n<pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python\n\n\'\'\'\nThis script makes a sparse checkout of an SVN tree in the current working directory.\n\nGiven a list of paths in an SVN repository, it will:\n1. Checkout the common root directory\n2. Update with depth=empty for intermediate directories\n3. Update with depth=infinity for the leaf directories\n\'\'\'\n\nimport os\nimport getpass\nimport pysvn\n\n__author__ = "Karl Ostmo"\n__date__ = "July 13, 2011"\n\n# =============================================================================\n\n# XXX The os.path.commonprefix() function does not behave as expected!\n# See here: http://mail.python.org/pipermail/python-dev/2002-December/030947.html\n# and here: http://nedbatchelder.com/blog/201003/whats_the_point_of_ospathcommonprefix.html\n# and here (what ever happened?): http://bugs.python.org/issue400788\nfrom itertools import takewhile\ndef allnamesequal(name):\n    return all(n==name[0] for n in name[1:])\n\ndef commonprefix(paths, sep=\'/\'):\n    bydirectorylevels = zip(*[p.split(sep) for p in paths])\n    return sep.join(x[0] for x in takewhile(allnamesequal, bydirectorylevels))\n\n# =============================================================================\ndef getSvnClient(options):\n\n    password = options.svn_password\n    if not password:\n        password = getpass.getpass(\'Enter SVN password for user "%s": \' % options.svn_username)\n\n    client = pysvn.Client()\n    client.callback_get_login = lambda realm, username, may_save: (True, options.svn_username, password, True)\n    return client\n\n# =============================================================================\ndef sparse_update_with_feedback(client, new_update_path):\n    revision_list = client.update(new_update_path, depth=pysvn.depth.empty)\n\n# =============================================================================\ndef sparse_checkout(options, client, repo_url, sparse_path, local_checkout_root):\n\n    path_segments = sparse_path.split(os.sep)\n    path_segments.reverse()\n\n    # Update the middle path segments\n    new_update_path = local_checkout_root\n    while len(path_segments) > 1:\n        path_segment = path_segments.pop()\n        new_update_path = os.path.join(new_update_path, path_segment)\n        sparse_update_with_feedback(client, new_update_path)\n        if options.verbose:\n            print "Added internal node:", path_segment\n\n    # Update the leaf path segment, fully-recursive\n    leaf_segment = path_segments.pop()\n    new_update_path = os.path.join(new_update_path, leaf_segment)\n\n    if options.verbose:\n        print "Will now update with \'recursive\':", new_update_path\n    update_revision_list = client.update(new_update_path)\n\n    if options.verbose:\n        for revision in update_revision_list:\n            print "- Finished updating %s to revision: %d" % (new_update_path, revision.number)\n\n# =============================================================================\ndef group_sparse_checkout(options, client, repo_url, sparse_path_list, local_checkout_root):\n\n    if not sparse_path_list:\n        print "Nothing to do!"\n        return\n\n    checkout_path = None\n    if len(sparse_path_list) > 1:\n        checkout_path = commonprefix(sparse_path_list)\n    else:\n        checkout_path = sparse_path_list[0].split(os.sep)[0]\n\n\n\n    root_checkout_url = os.path.join(repo_url, checkout_path).replace("\\\\", "/")\n    revision = client.checkout(root_checkout_url, local_checkout_root, depth=pysvn.depth.empty)\n\n    checkout_path_segments = checkout_path.split(os.sep)\n    for sparse_path in sparse_path_list:\n\n        # Remove the leading path segments\n        path_segments = sparse_path.split(os.sep)\n        start_segment_index = 0\n        for i, segment in enumerate(checkout_path_segments):\n            if segment == path_segments[i]:\n                start_segment_index += 1\n            else:\n                break\n\n        pruned_path = os.sep.join(path_segments[start_segment_index:])\n        sparse_checkout(options, client, repo_url, pruned_path, local_checkout_root)\n\n# =============================================================================\nif __name__ == "__main__":\n\n    from optparse import OptionParser\n    usage = """%prog  [path2] [more paths...]"""\n\n    default_repo_url = "http://svn.example.com/MyRepository"\n    default_checkout_path = "sparse_trunk"\n\n    parser = OptionParser(usage)\n    parser.add_option("-r", "--repo_url", type="str", default=default_repo_url, dest="repo_url", help=\'Repository URL (default: "%s")\' % default_repo_url)\n    parser.add_option("-l", "--local_path", type="str", default=default_checkout_path, dest="local_path", help=\'Local checkout path (default: "%s")\' % default_checkout_path)\n\n    default_username = getpass.getuser()\n    parser.add_option("-u", "--username", type="str", default=default_username, dest="svn_username", help=\'SVN login username (default: "%s")\' % default_username)\n    parser.add_option("-p", "--password", type="str", dest="svn_password", help="SVN login password")\n\n    parser.add_option("-v", "--verbose", action="store_true", default=False, dest="verbose", help="Verbose output")\n    (options, args) = parser.parse_args()\n\n    client = getSvnClient(options)\n    group_sparse_checkout(\n        options,\n        client,\n        options.repo_url,\n        map(os.path.relpath, args),\n        options.local_path)\n</code></pre>\n'}, {'answer_id': 53920270, 'author': 'Feng  Weiwei', 'author_id': 6320442, 'author_profile': 'https://Stackoverflow.com/users/6320442', 'pm_score': 1, 'selected': False, 'text': '<p>If you already have the full local copy, you can remove unwanted sub folders by using <code>--set-depth</code> command. </p>\n\n<pre><code>svn update --set-depth=exclude www\n</code></pre>\n\n<p>See: <a href="http://blogs.collab.net/subversion/sparse-directories-now-with-exclusion" rel="nofollow noreferrer">http://blogs.collab.net/subversion/sparse-directories-now-with-exclusion</a></p>\n\n<p>The <code>set-depth</code> command support multipile paths.</p>\n\n<p>Updating the root local copy will not change the depth of the modified folder.</p>\n\n<p>To restore the folder to being recusively checkingout, you could use <code>--set-depth</code> again with infinity param.</p>\n\n<pre><code>svn update --set-depth=infinity www\n</code></pre>\n'}, {'answer_id': 74054522, 'author': 'Zac', 'author_id': 971443, 'author_profile': 'https://Stackoverflow.com/users/971443', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m adding this information for those using the TortoiseSvn tool: to obtain the OP same functionality, you can use the <code>Choose items...</code> button in the <em>Checkout Depth</em> section of the Checkout function, as shown in the following screenshot:</p>\n<p><img src="https://i.stack.imgur.com/YetZO.jpg" alt="Images" /></p>\n'}]
['https://Stackoverflow.com/questions/50945', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4883/']