I have an SVN repository which was renamed from "Project" to "Project v1".
I then did a git svn clone
to create a git version of the renamed SVN folder.
When I git log
the newly created git repository, I only see a single history item. It's the commit message which I gave the SVN repository when I renamed the folder.
Is there a way for the git repository to have all of the SVN history prior to the folder being renamed (or any other possible renames prior to that one)?
The only way I have done this in the past (not knowing it's the best or only way!) was to explicitly git svn fetch
the prior history (you may need a second remote for this) and then graft the renamed tree onto the old history with git filter-branch
(there's a specific example in the docs for reparenting a tree).
From: svn://server/repo/project
To:svn://server/repo/project_v1
Optional first step: If you have no existing git-svn
repo for this, go ahead and git svn clone svn://server/repo/project
. Most people will probably already have this repo around because they have been working with git-svn
all along. If you have no git repo at all yet you can do the initial clone on either side.
In your git-svn
repo add a remote for the new name of the project. I don't think there's a command for this, you just add a stanza to your .git/config
very similar to the one that's already there:
[svn-remote "svn_v1"]
url = svn://server/repo/project_v1
fetch = :refs/remotes/git-svn-v1
That new SVN remote can be selected with the --remote svn_v1
option to any git-svn
command. The first thing you'll want to do is git-svn fetch --remote svn_v1
which will populate your git repo with the history of that copy. As the original question notes, this will be a very brief history!
Now we apply the example in the git filter-branch
manpage. You will need to know the tip of the old history, which is git show-ref -s remotes/git-svn
(again, assuming your original clone was the old version). Then use git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' remotes/git-svn-v1
where <graft-id>
is the SHA you just got for the tip of the old history.
Verify that this worked with git log remotes/git-svn-v1
and see all the history.
At this point you can go to your working branch and git reset --hard remotes/git-svn-v1
to switch that branch over to the new history.
Note that the svn-remote
named "svn" will be your default, so at the end you will want to rename the remotes in the [svn-remote "..."]
lines in your .git/config
so that your primary one is named "svn". You can name the other one -old
or even remote it.
Caveat: This is from memory and I have not just repeated these steps myself. Comments and corrections welcome.
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