7

I want to git clone an svn repository except for one folder in the root folder of svn.

How do I do it?

I could do git svn clone svnrepo/dir/sb-dir/ if I needed only sb-dir but I need all folders (and files) within the dir except the design folder

lprsd
  • 84,407
  • 47
  • 135
  • 168

2 Answers2

4

You can use the --ignore-paths=<regex> option to git svn init or git svn fetch, or add the config option svn-remote.<name>.ignore-paths to .git/config. This is documented as "This allows one to specify a Perl regular expression that will cause skipping of all matching paths from checkout from SVN." Search the manual for "ignore-paths" for more details.

After trying the experiment in this answer, I learned that the regex appears to be applied to the full path of each directory or file from the repository root. Therefore, if you have a standard repository layout and want to exclude the same thing from each trunk/branch/tag, you can use a regex like ^(trunk|((branches|tags)/[^/]+))/(<file-to-ignore>|<other-file-to-ignore>)(/|$).

Max Nanasy
  • 5,871
  • 7
  • 33
  • 38
  • 1
    This is the only place where I have found relatively useful regex to exclude a directory in all branches. But please: add a slash between trunk/branches part and the part where you describe what to exclude. Also, add a slash at the very end of the regex. – stgatilov Jun 08 '19 at 17:38
  • @stgatilov Thanks for the suggestions :) I added a slash between the branches and the files, but I didn't add a slash to the end, because the regular expression works for both folders and files this way, and none of the examples in [the documentation](https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-svn.html) have a trailing slash – Max Nanasy Jun 16 '19 at 23:55
  • 1
    @stgatilov Upon closer inspection, it seems that a regex like `file-a` also matches e.g. `file-abc`, which makes both my answer's regex and the regexes in the documentation unsafe. I've added `(/|$)` to the end of the regex, which should fix this issue for both files and folders – Max Nanasy Jun 17 '19 at 00:21
3

If you are using the latest Git1.7.0, it offers a sparse checkout feature.

"sparse checkout" feature allows only part of the work tree to be checked out.

See Git Sparse Checkout SO question for more: you still need to clone the all repo, but you can checkout (i.e. fill your working tree) with only parts of the cloned repo)


The only other way would to transform design as a submodule.
As the GitPro book mentions:

Git's submodule support allows a repository to contain, as a subdirectory, a checkout of an external project.
Submodules maintain their own identity; the submodule support just stores the submodule repository location and commit ID, so other developers who clone the containing project ("superproject") can easily clone all the submodules at the same revision.
Partial checkouts of the superproject are possible: you can tell Git to clone none, some or all of the submodules.

Submodule is the only way I am aware to achieve "partial cloning", since n your case it is the cloning part which is problematic.
From your comments:

my problem is that design folder is some 700 mb; and it takes hours to git svn clone. Whole of the rest of the project put together is in 10s of mb.

But that means modifying the SVN repo, to isolate design as an "external" reference, then git svn clone and add in the cloned Git repo a submodule reference.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks! But my problem is that design folder is some 700 mb; and it takes hours to git svn clone. Whole of the rest of the project put together is in 10s of mb. It is wrong in the first place I know, to put it in repo. But I wanted some sane way to deal locally using git. Doesn;t seem possible, then – lprsd Mar 03 '10 at 14:51
  • @becomingGuru: the sane way would be to split that repo and isolate design in its own repo, referenced as a submodule. That way, you would achieve *exactly* what you are looking for. See http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository – VonC Mar 03 '10 at 15:02