views:

1081

answers:

3

I already have a svn read only repo checked out (svn co and not git svn). I have made some changes and commits using git which is then pushed up to github.

At this point, git does not have all of the history from svn. I was wondering if there was a way to extract and import this at this point.

The various git-svn guides show how to import a clean repo and transfer the history but not one that I can find that is already in use.

+1  A: 

You will probably have to do an svn import into a fresh git repository, merge the two repositories (just add them together, it will probably complain about them being unrelated) and then rebase the changes you made unto the imported history.

Thilo
+2  A: 

To complete Thilo's good answer, once you have imported the svn repo into a git one, you can add that git repository into yours with a script as detailed in merging in unrelated git branches

#!/bin/bash

set -e

if test -z "$2" -o -n "$3"; then
    echo "usage: $0 REPO BRANCHNAME" >&2
    exit 1
fi

repo=$1
branch=$2

git fetch "$repo" "$branch"

head=$(git rev-parse HEAD)
fetched=$(git rev-parse FETCH_HEAD)
headref=$(git rev-parse --symbolic-full-name HEAD)

git checkout $fetched .

tree=$(git write-tree)

newhead=$(echo "merged in branch '$branch' from $repo" | git commit-tree $tree -p $head -p $fetched)
git-update-ref $headref $newhead $head
git reset --hard $headref

Other methods includes:

  • try a "simple" git pull REPO BRANCH
  • using git grafts to restore svn merge history by creating a text file at .git/info/grafts, where each line contains a commit id followed by its parents. Your local repository will henceforth act as if that commit actually descended from both parents.
VonC
+1  A: 

I tried a bunch of things but ended up just pulling the svn repo from scratch again and manually applying the changes before pushing to a new github repo. The problem I was getting was that any git svn fetch/rebase would end up trying to replay things back and forth.

Quick summary of what I tried first (This did NOT do what I wanted. Would be helpful if someone pointed out where I went wrong)

svn co http://repo/source/branches/branch
git init
git add . 
git remote add origin [email protected]:user/repo.git

changes made

git add .
git commit -a
git push origin master

Above is what I had done prior to starting this experiment.

git svn clone http://repo/source/branches/branch
git remote add origin [email protected]:user/repo.git
git pull origin master
git diff
git commit -a

This seemed to work. So I proceeded to try to get things up to date.

git svn fetch
git svn rebase
git pull origin master
git push origin master

This is when things started going egg shaped. I would get errors like the following.

a001:~/src/grr$ git svn rebase
First, rewinding head to replay your work on top of it...
HEAD is now at 09d15f4... Merged revisions 34908-34917 via svnmerge from 1.2-trunk
Applying fix url escape
Applying fix url escape
error: patch failed: app/code/core/Mage/Page/Block/Html/Head.php:132
error: app/code/core/Mage/Page/Block/Html/Head.php: patch does not apply
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.


Eventually, I gave up and did the following instead.

git svn clone http://repo/source/branches/branch
git add .
git commit -a
git remote add origin [email protected]:user/repo.git
git push origin master
Jauder Ho