Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to import svn history into git after the fact?

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.

like image 612
Jauder Ho Avatar asked Mar 10 '09 06:03

Jauder Ho


People also ask

Which migration is actually recommended for migration from SVN to Git?

When moving to Git from another version control system like Subversion (SVN), we generally recommend that you perform a "tip migration", which migrates just the latest version of the repository contents, without including history.

Can you use Git and SVN together?

git-svn is a specialized tool for Git users to interact with Git repositories. It works by providing a Git frontend to an SVN backend. With git-svn, you use Git commands on the local repository, so it's just like using normal Git. However, behind the scenes, the relevant SVN commands are sent to the server.

Why do people prefer Git over SVN?

Many people prefer Git for version control for a few reasons: It's faster to commit. Because you commit to the central repository more often in SVN, network traffic slows everyone down. Whereas with Git, you're working mostly on your local repository and only committing to the central repository every so often.


2 Answers

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.
like image 197
VonC Avatar answered Oct 14 '22 15:10

VonC


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.

like image 36
Thilo Avatar answered Oct 14 '22 15:10

Thilo