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
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.
GitHub repositories can be accessed from both Git and Subversion (SVN) clients.
By default git-svn
stores mapping between SVN revisions and Git commits in commit messages. Do you see these git-svn-id
lines 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:
$ git clone $GIT_SERVER repo
$ cd repo
Update git-svn configuration in .git/config:
$ git config svn-remote.svn.url $SVN_URL
$ git config svn-remote.svn.fetch trunk:refs/remotes/trunk
$ git config svn-remote.svn.branches branches/*:refs/remotes/*
$ git config svn-remote.svn.tags tags/*:refs/remotes/tags/*
Now you have to update refs/remotes/* refs to the latest commits with git-svn-id line:
$ git log --first-parent refs/heads/master
commit d566edf5f77ae0a2f7418c40949757e75ef8e83c
D
commit 4df9f21346526c6505a954d8310637864710308d
C
git-svn-id: $SVN_URL .../trunk@3...
commit 116a6760d3e278aa4d54f5bb22e531d30d731661
B
git-svn-id: $SVN_URL .../trunk@2...
commit d8bb201c6fd55ea5e645f2d8a07248593d177910
A
git-svn-id: $SVN_URL .../trunk@1...
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:
$ git update-ref refs/remotes/trunk 4df9f21346526c6505a954d8310637864710308d
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:
$ git svn fetch
Migrating from a git-svn v1 layout...
Data from a previous version of git-svn exists, but
.git/svn
(required for this version (X.Y.Z) of git-svn) does not exist.
Done migrating from a git-svn v1 layout
Rebuilding .git/svn/refs/remotes/trunk/.rev_map.694389ff-b137-4359-84f9-4d1a25628e89...
r1 = d8bb201c6fd55ea5e645f2d8a07248593d177910
r2 = 116a6760d3e278aa4d54f5bb22e531d30d731661
r3 = 4df9f21346526c6505a954d8310637864710308d
Done rebuilding .git/svn/refs/remotes/trunk/.rev_map.694389ff-b137-4359-84f9-4d1a25628e89
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:
$ git svn rebase
$ git svn dcommit
Hope that helps.
First, I'd check the output of the git svn info
command. Do you see some strange things there?
Second, the thing is that it is not a good idea to use git svn
with a secondary git repository other than your local one.
The reason is that after each git svn dcommit
git automatically rewrites all the commits you made previously: first it commits them back to svn and then adds the svn revision number for the commit (in a unique identifier called git-svn-id
).
It should be something like this in a repository where you made a new dcommit
:
$ git log -1
commit 1234abc...
Author: ...
Date: ...
Some commit message
git-svn-id: http://your.svn.repo/svn/trunk@10 1234abc
About the details, here is a section from the ProGit book.
The error message you wrote is probably warning: no common commits
(not conflicts
as you wrote in the question), and my impression is that git did not pushed these metadata into the remote repo.
I think you can raise this SVN link from the dead, but be careful, make it on a separate clone of the repo, and read the documentation carefully about what metadata it needs. In git, you can do quite a lot of things with the plumbing tools, take a look on them.
Btw cannot you simply clone the remote git repo and use that?
Hope this helps something, or at least give you a few ideas where you can start looking for a solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With