mattsun mattsun - 1 month ago 7x
Git Question

Import history to existing Git project from SVN

There is a project has been on GitHub for a while, but previously it was migrated from svn. When it was initially migrated, SVN history wasn't carried to Git. Is there a way that can copy/import/clone/move SVN history to Git after the project has been set up?


git-svn is not the right tool for one-time conversions of repositories. It is a great tool if you want to use Git as frontend for an existing SVN server, but for one-time conversions you should not use git-svn, but svn2git which is much more suited for this use-case.

There are pleny tools called svn2git, the probably best one is the KDE one from I strongly recommend using that svn2git tool. It is the best I know available out there and it is very flexible in what you can do with its rules files.

If you are not 100% about the history of your repository, svneverever from is a great tool to investigate the history of an SVN repository when migrating it to Git.

After you converted your SVN repo to a proper Git repo, add your newly generated repo as remote to your existing repo and fetch the commits. Then use git replace to replace the first commit of your new history with the last commit of your old history. If you want to make this permanent, you can then use git filter-branch to make the replacement permanent.

Be aware that you will rewrite published history and that everyone having local branches based on the former history will have to recover from this history change like described in the documentation of git rebase. If you don't want this, you can also simply pull in the newly migrated repo into your Git repo and just create new branches from the SVN history. You will then have multiple root commits and independent histories which technically is ok, but you will still have a cut in the history of the files.