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?
- You could make a new clone based on the Subversion history, and then try to merge those changes into your existing Git repository. Note that you won’t be able to introduce that Subversion history as a base for the existing Git history, but you could have it as a parallel history which you will merge now.poke– poke2016-07-15 07:12:36 +00:00Commented Jul 15, 2016 at 7:12
- @poke why should he not be able to? Of course he is. Of course he will rewrite published history with this and anyone using the repo must recover by rebasing all their branches manually like always with changed published history.Vampire– Vampire2016-07-16 21:35:13 +00:00Commented Jul 16, 2016 at 21:35
- @Vampire He cannot without rewriting history, that's what I meant. If the project has been active for a while, it seems like a good idea to keep the history as it is.poke– poke2016-07-16 21:38:41 +00:00Commented Jul 16, 2016 at 21:38
2 Answers
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 https://github.com/svn-all-fast-export/svn2git. 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 http://blog.hartwork.org/?p=763 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.
Comments
That's possible but you will impact all the users that already cloned the repository. So you have to decide first if it worth it.
If it isn't, just clone with git-svn in another git repository and keep it there for the source code history...
If you want to go further, once the history is retrieved, add this new repository as a remote in your actual repository and fetch.
git fetch --all Once that's done, you should have a disjoint history.
Then, use 'git replace' to replace the first commit of the new repository by the last of the branch you just fetched.
https://git-scm.com/docs/git-replace
And last, use 'git filter-branch', that will rewrite the history definitely.
You will have to push the new history, with something like :
git push origin --all And all the other developers will have to clone or fetch all the history... And will complain ;-)
2 Comments
merging you don't say fetching, like I describe. Otherwise you're going to straight to hell... :() but mine is easier....