threads / discuss / 14915

Converting from svn to git

Subject: Converting from svn to git

## tl;dr

8 messages between Aug 10, 2008 and Aug 17, 2008.

replies: 7people: 4as markdown or json

David Neu· Aug 10, 2008, 13:11 UTC · lore
Hi,

I'm trying to move an svn repo to git. I'm not going to be committing back to the svn repo, but will simply retire it and use git.

The issue I'm having is that the svn repo has sub directories that I'd like to be separate git repos.

I can easily accomplish this for the sub directories like this:

git-svn clone svn-url/subdir1 git-svn clone svn-url/subdir2 etc.

but for the files in the base directory
git-svn clone svn-url
pulls the entire directory tree.

Is there a git-svn strategy similar to git-svnimport -P that would do the trick? My git version 1.5.6.4 doesn't include git-svnimport, and I'm getting the impression it's be deprecated.

Many thanks for any help!

Cheers, David

Miklos Vajna· Aug 10, 2008, 13:24 UTC · re: David Neu · lore

Re: Converting from svn to git

On Sun, Aug 10, 2008 at 09:11:43AM -0400, David Neu <david@davidneu.com> wrote:
> Is there a git-svn strategy similar to git-svnimport -P that would do the trick?
> My git version 1.5.6.4 doesn't include git-svnimport, and I'm getting
> the impression
> it's be deprecated.

Sure, it is. Though if you _really_ need it, it's still under /contrib/examples.

Anyway, if you do a single conversion, then probably speed does not matter a lot; I would do a full import then use the subdirectory-filter of git filter-branch do drop everything outside the subdirectory.

David Neu· Aug 10, 2008, 14:54 UTC · re: Miklos Vajna · lore

Re: Converting from svn to git

Thanks for the reply - this looks like what I'd need, but I can't see how to keep the contents of the base dir and lose the subdirs, e.g.

$ git-filter-branch --subdirectory-filter . HEAD
removes all subdirs and the contents of the base dir.
So, I figure I'd remove each subdir, using
$ git-filter-branch --tree-filter 'rm -rf subdir1/' HEAD

but this complains if subdir1 contains subdirectories, it says: Namespace refs/original/ not empty

Many thanks!

Cheers, David

On Sun, Aug 10, 2008 at 9:24 AM, Miklos Vajna <vmiklos@frugalware.org> wrote:
Show 13 quoted lines
>
> On Sun, Aug 10, 2008 at 09:11:43AM -0400, David Neu <david@davidneu.com> wrote:
> > Is there a git-svn strategy similar to git-svnimport -P that would do the trick?
> > My git version 1.5.6.4 doesn't include git-svnimport, and I'm getting
> > the impression
> > it's be deprecated.
>
> Sure, it is. Though if you _really_ need it, it's still under
> /contrib/examples.
>
> Anyway, if you do a single conversion, then probably speed does not
> matter a lot; I would do a full import then use the subdirectory-filter
> of git filter-branch do drop everything outside the subdirectory.
Michael J Gruber· Aug 10, 2008, 15:32 UTC · re: David Neu · lore

Re: Converting from svn to git

David Neu venit, vidit, dixit 10.08.2008 16:54:
Show 14 quoted lines
> Thanks for the reply - this looks like what I'd need, but
> I can't see how to keep the contents of the base dir and
> lose the subdirs, e.g.
> 
> $ git-filter-branch --subdirectory-filter . HEAD
> 
> removes all subdirs and the contents of the base dir.
> 
> So, I figure I'd remove each subdir, using
> 
> $ git-filter-branch --tree-filter 'rm -rf subdir1/' HEAD
> 
> but this complains if subdir1 contains subdirectories, it
> says: Namespace refs/original/ not empty

It complains because filter-branch stores the original refs in that namespace, and on the second filter-branch run it wants to do this again. You can avoid this by using the "-f" option to filter-branch, or by removing all subsirs in one go ("rm -rf subdir1 subdir2..."). Also, you might want to rewrite all refs ("--all"), not just HEAD.

Michael
David Neu· Aug 10, 2008, 15:48 UTC · re: Michael J Gruber · lore

Re: Converting from svn to git

That's great - thanks to everyone!

On Sun, Aug 10, 2008 at 11:32 AM, Michael J Gruber <michaeljgruber+gmane@fastmail.fm> wrote:

Show 30 quoted lines
> David Neu venit, vidit, dixit 10.08.2008 16:54:
>>
>> Thanks for the reply - this looks like what I'd need, but
>> I can't see how to keep the contents of the base dir and
>> lose the subdirs, e.g.
>>
>> $ git-filter-branch --subdirectory-filter . HEAD
>>
>> removes all subdirs and the contents of the base dir.
>>
>> So, I figure I'd remove each subdir, using
>>
>> $ git-filter-branch --tree-filter 'rm -rf subdir1/' HEAD
>>
>> but this complains if subdir1 contains subdirectories, it
>> says: Namespace refs/original/ not empty
>
> It complains because filter-branch stores the original refs in that
> namespace, and on the second filter-branch run it wants to do this again.
> You can avoid this by using the "-f" option to filter-branch, or by removing
> all subsirs in one go ("rm -rf subdir1 subdir2..."). Also, you might want to
> rewrite all refs ("--all"), not just HEAD.
>
> Michael
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
David Neu· Aug 11, 2008, 17:46 UTC · re: David Neu · lore

Re: Converting from svn to git

OK, I did
$ git-filter-branch --tree-filter 'rm -rf subdir1/ subdir2/ subdir3/' -- --all

which looks good, except when I open gitk, I still see "empty" commits that correspond to subdir1/, subdir2/ and subdir3/.

Is there anyway to remove those?
Many thanks!

Cheers, David

On Sun, Aug 10, 2008 at 11:48 AM, David Neu <david@davidneu.com> wrote:
Show 35 quoted lines
> That's great - thanks to everyone!
>
> On Sun, Aug 10, 2008 at 11:32 AM, Michael J Gruber
> <michaeljgruber+gmane@fastmail.fm> wrote:
>> David Neu venit, vidit, dixit 10.08.2008 16:54:
>>>
>>> Thanks for the reply - this looks like what I'd need, but
>>> I can't see how to keep the contents of the base dir and
>>> lose the subdirs, e.g.
>>>
>>> $ git-filter-branch --subdirectory-filter . HEAD
>>>
>>> removes all subdirs and the contents of the base dir.
>>>
>>> So, I figure I'd remove each subdir, using
>>>
>>> $ git-filter-branch --tree-filter 'rm -rf subdir1/' HEAD
>>>
>>> but this complains if subdir1 contains subdirectories, it
>>> says: Namespace refs/original/ not empty
>>
>> It complains because filter-branch stores the original refs in that
>> namespace, and on the second filter-branch run it wants to do this again.
>> You can avoid this by using the "-f" option to filter-branch, or by removing
>> all subsirs in one go ("rm -rf subdir1 subdir2..."). Also, you might want to
>> rewrite all refs ("--all"), not just HEAD.
>>
>> Michael
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
Michael J Gruber· Aug 15, 2008, 13:58 UTC · re: David Neu · lore

Re: Converting from svn to git

David Neu venit, vidit, dixit 11.08.2008 19:46:
Show 8 quoted lines
> OK, I did
> 
> $ git-filter-branch --tree-filter 'rm -rf subdir1/ subdir2/ subdir3/' -- --all
> 
> which looks good, except when I open gitk, I still see "empty" commits
> that correspond to subdir1/, subdir2/ and subdir3/.
> 
> Is there anyway to remove those?

A while ago I "complained" that rebase would skip empty commits. You might experiment with that. Alternatively, the following works for me:

git filter-branch --commit-filter 'cmd="git commit-tree"; test `git show --pretty=oneline $GIT_COMMIT|wc -l` = 1 && cmd="skip_commit"; $cmd "$@"' -- --all

This skips all commits which introduce no diff. It will not remove branches or tags which are related only to those subdirs.

I am sure there will be more elegant ways to do that (esp. the test with wc).

Michael
Sam Vilain· Aug 17, 2008, 09:11 UTC · re: Michael J Gruber · lore

Re: Converting from svn to git

On Fri, 2008-08-15 at 15:58 +0200, Michael J Gruber wrote:
Show 12 quoted lines
> A while ago I "complained" that rebase would skip empty commits. You 
> might experiment with that. Alternatively, the following works for me:
> 
> git filter-branch --commit-filter 'cmd="git commit-tree"; test `git show 
> --pretty=oneline $GIT_COMMIT|wc -l` = 1 && cmd="skip_commit"; $cmd "$@"' 
> -- --all
> 
> This skips all commits which introduce no diff. It will not remove 
> branches or tags which are related only to those subdirs.
> 
> I am sure there will be more elegant ways to do that (esp. the test with 
> wc).
something like this should work:
  --commit-filter 'if [ "$1" = `git rev-parse HEAD^{tree}` ]; then
skip_commit "$@"; else git commit-tree "$@"; fi'
Sam.

← back to recent threads