git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Getting correct tree layout when importing svn repo into git

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Sep 17, 2008, 13:04 UTC
Message-ID
<48D1005C.2090401@drmicha.warpmail.net>
In-Reply-To
<cfd18e0f0809170600r79d883d3t96abb49e827d3178@mail.gmail.com>
Michael Kerrisk venit, vidit, dixit 17.09.2008 15:00:
Show 135 quoted lines
> Michael,
> 
> On Wed, Sep 17, 2008 at 4:14 AM, Michael J Gruber
> <git@drmicha.warpmail.net> wrote:
>> Michael Kerrisk venit, vidit, dixit 17.09.2008 12:38:
>>> Hello Michael,
>>>
>>> On Wed, Sep 17, 2008 at 1:25 AM, Michael J Gruber
>>> <git@drmicha.warpmail.net> wrote:
>>>> Michael Kerrisk venit, vidit, dixit 17.09.2008 00:05:
>>>>> Hello,
>>>>>
>>>>> I'm currently trying to import an svn repository, along with its tags,
>>>>> into git, and everything seems okay except that after the import I
>>>>> expect to have the following structure to my checked out repository:
>>>>>
>>>>>     [root-dir]
>>>>>         .git
>>>>>         <checked-out-files>
>>>>>
>>>>> But instead I end up with
>>>>>
>>>>>     [root-dir]
>>>>>         .git
>>>>>         man-pages               <-- name of my svn project
>>>>>             <checked-out-files>
>>>>>
>>>>> I've tried out a few different command-line flag settings but so far I
>>>>> haven't managed to get the desired layout.  I guess that I'm missing
>>>>> something trivial, but I haven't worked out what it is so far.
>>>>>
>>>>> The commands I'm using to do the import are:
>>>>>
>>>>> $ git svn init file:///home/mtk/man-pages-rep/ -t tags -T trunk -b branches
>>>>> $ git svn fetch
>>>>>
>>>>> The svn tags are getting imported okay, since:
>>>>>
>>>>> git branch -a | head
>>>>>   tags/man-pages-2.00
>>>>>   tags/man-pages-2.01
>>>>>   ...
>>>>>   tags/man-pages-3.08
>>>>>   tags/man-pages-3.09
>>>>>   trunk
>>>>>
>>>>> The following commands show the layout of my svn repo, which is pretty
>>>>> much standard:
>>>>>
>>>>> $ svn list file:///home/mtk/man-pages-rep
>>>>> branches/
>>>>> tags/
>>>>> trunk/
>>>>> $ svn list file:///home/mtk/man-pages-rep/trunk
>>>>> man-pages/
>>>> That's the part that says that your layout is non-standard. What do your
>>>>  branches and tags look like? Do they have that superfluous "man-pages"
>>>> part as well?
>>> $ svn list file:///home/mtk/man-pages-rep/tags
>>> man-pages-2.00
>>> man-pages-2.01
>>> man-pages-2.02
>>> man-pages-2.03
>>> ...
>>> $ svn list file:///home/mtk/man-pages-rep/tags/man-pages-2.00
>>> man-pages
>>> $ svn list file:///home/mtk/man-pages-rep/tags/man-pages-2.01
>>> man-pages
>>> [and so on]
>> Bingo!
>>
>>> $ svn list file:///home/mtk/man-pages-rep/branches
>>> $
>>> (i.e., no branches, since this has been a linear svn repo.)
>> git-svn converts svn tags into git branches (because they can change).
>> So you will get a git repo with lots of branches which are subsets (HEAD
>> commit is in master/trunk) of master/trunk.
>>
>>>>> $ svn list file:///home/mtk/man-pages-rep/trunk/man-pages
>>>>> Changes
>>>>> Changes.old
>>>>> Makefile
>>>>> README
>>>>> man-pages-3.09.Announce
>>>>> ...
>>>>> man7/
>>>>> man8/
>>>>> scripts/
>>>>> $ svn list file:///home/mtk/man-pages-rep/tags
>>>>> man-pages-2.00/
>>>>> man-pages-2.01/
>>>>> ...
>>>>> man-pages-3.08/
>>>>> man-pages-3.09/
>>>>>
>>>>> What 'git svn init' command do I need to get the layout that I want
>>>>> for my imported git repo?
>>>> It depends on the structure of your branches and tags. My guess would be
>>>> that you have something like tags/man-pages-2.00/man-pages/ etc., in
>>>> which case you would need a special configuration if you want to get rid
>>>> of the "man-pages" part. Tells us your structure, we'll tell you the
>>>> config ;)
>>> Do you now have enough info above?
>> Yes, thanks. If you use git-svn init -s (which is equivalent to -T trunk
>> -t tags -b branches) you get an "exact" clone of your svn repo in
>> reasonable time, as you already noticed.
>>
>> In order to get rid of the "man-pages" path component you can either:
>>
>> - remove it after the fact using git filter-branch
>>
>> or
>>
>> - remove it during the conversion process
>>
>> For the latter, do the following:
>>
>> git svn init -s file:///home/mtk/man-pages-rep/
>>
>> as usual. Then, before the first fetch, make sure your .git/config svn
>> section looks as follows:
>>
>> [svn-remote "svn"]
>>        url = file:///home/mtk/man-pages-rep/
>>        fetch = trunk/man-pages:refs/remotes/trunk
>>        branches = branches/*/man-pages:refs/remotes/*
>>        tags = tags/*/man-pages:refs/remotes/tags/*
> 
> I guess your solution here was equivalent to Björn's, since after I
> tried his suggestion, I ended up with an [svn-remote "svn"] that looks
> just as you describe.
> 
> Thanks,
> 
> Michael

Yes. You mentioned you used an old version. Newer ones accept the parameters in the way Björn described. Older ones accepted the same config, just not as parameters.

That kind of config is well-suited for splitting large svn-repos which consist of well-separated subprojects.

So, welcome among the happy svn->git converts ;)
Michael
Show 10 quoted lines
>> That is, if you used "git svn init -s" you only have to add "/man-pages"
>> three times on the left hand side of the refspecs. You can also do this
>> using "git config", of course, if you watch out for the shell quoting.
>>
>> Cheers,
>> Michael
>>
> 
> 
> 
Previous: Michael Kerrisk
Message 17 of 17 in “Getting correct tree layout when importing svn repo into git”
  1. Michael KerriskSep 16, 2008
  2. Dmitry PotapovSep 16, 2008
  3. Michael KerriskSep 16, 2008
  4. Dmitry PotapovSep 17, 2008
  5. Michael KerriskSep 17, 2008
  6. Andreas EricssonSep 17, 2008
  7. Michael KerriskSep 17, 2008
  8. Michael GebetsroitherSep 17, 2008
  9. Björn SteinbrinkSep 17, 2008
  10. Michael KerriskSep 17, 2008
  11. Michael J GruberSep 17, 2008
  12. Michael KerriskSep 17, 2008
  13. Björn SteinbrinkSep 17, 2008
  14. Michael KerriskSep 17, 2008
  15. Michael J GruberSep 17, 2008
  16. Michael KerriskSep 17, 2008
  17. Michael J GruberSep 17, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.