git merge between different repositories
Question
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
Solution
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.
OTHER TIPS
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.