I used git svn to import an existing Subversion repo into git. I then pushed this to git repo on a git server. Over the last few months changes to the software have been made in both Subversion and git repositories. Unfortunately, my local copy with the links between svn and git has been deleted.
I’ve tried to recreate the local copy using git svn again, but when I do a pull from the git server it complains warning: no common conflicts and I end up merging two separate branches with the same commits at the start. Like this:
F
|\
| \
E D
| |
C C
| |
B B
| |
A A
How can I get it to treat the svn changes like they happened on a branch from the original repo?
F
|\
| \
E D
| /
|/
C
|
B
|
A
By default
git-svnstores mapping between SVN revisions and Git commits in commit messages. Do you see thesegit-svn-idlines for older commits in your original Git repository? Here I mean that Git repository hosted on the Git server and not that one you’ve fetched from SVN recently.If so, you actually didn’t loose any links and git-svn should be able to restore the necessary data from the history. Though due to some compatibility issues between different versions of git-svn this may be a bit tricky:
Clone your original Git repository:
Update git-svn configuration in .git/config:
Now you have to update refs/remotes/* refs to the latest commits with git-svn-id line:
As you can see commit D does not have git-svn-id line, but commit C has one and that line refers to trunk, so you have to update refs/remotes/trunk to commit C:
If you have many branches and tags, repeat the same steps for them with respect to the mapping we’ve specified above:
branches/foo => refs/remotes/foo
tags/1.0 => refs/remotes/tags/1.0
The final step is to restore the mapping in .git/svn directory:
The last command also fetches new revisions from SVN server. After the command is done you have a git-svn clone of Subversion repository. The history in this repository has diverged, so you have to synchronize changes between SVN and Git repositories as usually:
Hope that helps.