44

I am completely unable to find any explanation how I should specify location of existing svn repository.

In other words - what should be used as URL in

git svn clone URL

when svn repository is local?

Bulwersator
  • 1,102
  • 2
  • 12
  • 30

2 Answers2

65

You should be able to succeed like this:

git svn clone file:///e/svn_repo_on_E_drive

Similar to svn checkout command:

svn co file:///e/svn_repo_on_E_drive

file:// for folder on the current drive of the executing CMD prompt, file:///d/some_folder for D:\some_folder.

Note: The extra / and the removed colon : in the file link on Windows. file://e:/svn_repo_on_E_drivefile:///e/svn_repo_on_E_drive

git svn clone also works on remote svn repos

# for example
git svn clone https://your.hostname/path/here/svn/
  • note: git svn clone gets all commits, as opposed to svn checkout only getting the most recent file set, and so the shell command can take a long time if the svn repo has lots of commits and/or files.
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
zionyx
  • 1,927
  • 19
  • 14
  • 15
    I was having a problem with this approach until I removed the colon (:) from drive on the file URL. Usually, in windows you see this file:///e:/svn_repo_on_E_drive , but for git you need to remove the ':' from the drive, leaving file:///e/svn_repo_on_E_drive – kurast Feb 20 '17 at 13:49
  • Thanks @kurast, i'll make the answer more obvious to remove it. – zionyx Feb 20 '17 at 20:35
  • 3
    For me it does not work in any combination of /// and other things: Can't create session: Unable to connect to a repository at URL 'file://d/temp/xxxx': Local URL 'file://d/temp/xxxx' contains unsupported hostname at / mingw64/share/perl5/site_perl/Git/SVN.pm line 144. – flohack Jun 04 '18 at 19:19
  • @flohack, based on the syntax, i assume you are using the command on Windows? Have you tried `file:///d/temp/xxxx`? What's the full command used when you get the error? – zionyx Jun 06 '18 at 11:44
  • 3
    With 3 /// I get slightly different result: $ git svn clone file:///d/temp/xxxx/ Initialized empty Git repository in D:/yyyy.lt/git/xxxx/.git/ Can't create session: Unable to connect to a repository at URL 'file:///d/temp/xxxx': Unable to open repository 'file:///d/temp/xxxx' at /mingw64/share/perl5/site_perl/Git/SVN.pm line 144. – flohack Jun 06 '18 at 17:58
  • Unfortunately no. I am able to reproduce the same error you guys get. Which means, the behavior of Git has changed over time? Hmm. – zionyx Jun 28 '18 at 19:51
  • I finally installed svn+ssh server only to do this import :) – flohack Jul 02 '18 at 10:47
  • Yes, of course, you can use svnserve to serve so you can use `svn://` over `file:///`. A great workaround! – zionyx Jul 03 '18 at 19:05
  • Try to create a symbolic link of the repository in a different drive to the new location, then you do not need to mess with drive letters in your `file:///`. – zionyx Jul 06 '18 at 10:13
  • 1
    Your reply saved my old repo which i was going to dump. Unable to find anywhere else: file://e:/svn_repo_on_E_drive → file:///e/svn_repo_on_E_drive – Azghanvi May 12 '21 at 02:58
  • Can not make it work. Got this error: ```Unable to open repository 'file:///d/projects/xxx' at C:/Program Files/Git/mingw64/share/perl5/Git/SVN.pm line 310.``` I am using the git version of ```version 2.34.0.windows.1```. – bitmountain Nov 19 '21 at 03:15
9

For a local repository you use a file:// URL, same as would be used for doing a checkout with the normal svn client.

If you're trying to copy the entire history, and using git svn clone --stdlayout just use the URL that you would use to checkout the trunk with svn minus the /trunk portion at the end.

qqx
  • 18,947
  • 4
  • 64
  • 68
  • 2
    So file:///X:/path/to/repos should work? Weird, as it fails with "Couldn't open a repository: Unable to open an ra_local session to URL: Unable to open repository" – Bulwersator Mar 13 '13 at 22:06
  • 3
    `file://` URLs work for me. No idea about the drive specifier portion, I don't use windows. – qqx Mar 13 '13 at 22:44
  • 2
    From your last comment I suppose you're using Windows. Try to remove the third "/". Maybe it doesn't work because there's a bug: https://code.google.com/p/tortoisegit/issues/detail?id=1402 – Francesco Frassinelli Mar 14 '13 at 14:53
  • 9
    You need to remove the colon ( : ) from the drive letter. So instead of file:///X:/path/to/repos you need to use file:///X/path/to/repos – Crayon Dec 19 '15 at 15:38