1

I created a repository with git-svn from a big svn repository (git svn clone). I've several local commits in my git repository that I don't need to push to svn but I will need to get updates from it.

Now I realized that I don't need the entire svn history in my local repository, since it's using too much space (some Gb) and that I should have used the -r option in the clone command to select a starting point.

I'd linke to start over with a new repository and then merge all the local commits from the old repository, but I'm not sure there is a simple way to do this.

The situation is this:

log of the old repository:

  • local commit 10
  • local commit 9 ...
  • local commit 1
  • svn revision X
  • svn revision X-1 ...
  • svn revision 1

the new repository has just one commit, corresponding to the contend of the revision X of the svn repository.

I tried to use format-patch and apply commands but I'm not sure on how to do this.

Is there a way to do what I need?

Thanks for any help

Andrea Polci
  • 1,011
  • 13
  • 27

2 Answers2

2

One method is, in your new repository:

  • to git remote add old your old repository;
  • to git fetch old;
  • to checkout the branch which contains you want;
  • to know the starting point from where your branch was created before the changes;
  • and then use git rebase --onto.

When done, git remote rm the old repo and git gc.

See git help rebase for the --onto option: it is very, very useful.

fge
  • 119,121
  • 33
  • 254
  • 329
  • I followed your method with one variation to make it more efficient. Instead of adding the old repository to the new one I added the new repository to the old one and pushed changes after the rebase. Thanks for your help. – Andrea Polci Dec 19 '11 at 10:20
2

You could begin with checking out the revision X from the SVN repository and getting rid of all SVN-related folders. Then git init && git add . && git commit -m "Importing revision X from SVN". Now you've got a Git repository with a snapshot of SVN's revision X.

Afterwards you could use git format-patch to create patches from your old Git repository. git format-patch x.. where x is the commit equivalent to revision X from SVN. It will generate patch files. Execute it in the old Git repository.

Subsequently, in the new repository you can git am all_those_patches.* to get them applied in the new repository.

Cf. man git-am, man git-format-patch.

Jan
  • 11,636
  • 38
  • 47
  • Yep, much more space efficient than mine. Actually I wondered about `git am` but I remember now that format-patch generates in order, so globbing will yield them in the correct order. – fge Dec 16 '11 at 17:06
  • If I understand I can replace the first step with `git clone -r `, right? I tried to follow your instructions but when I `do git am ...` I get the following error for the first patch: `Applying: commit log error: patch failed: some/path/filename.xml:12 error: some/path/filename.xml: patch does not apply Patch failed at 0001 commit log When you have resolved this problem run "git am --resolved". If you would prefer to skip this patch, instead run "git am --skip". To restore the original branch and stop patching run "git am --abort".` – Andrea Polci Dec 19 '11 at 09:02