I have a git repo, and my company assigned me an empty svn repo to store my code in. So what I'd like to do is just add that svn repo as a remote to my existing git repo and then push to it.
Now, all git-svn tutorials start with "first clone the svn repo, then add code". That doesn't work for me, since I already have an existing git repo.
I also found some tutorials for importing of svn branches to git repo, but that also is not what I need, I need to import git repo into a svn repo.
I tried to simply do a git svn init http://remote-repo
, and then git svn rebase
, but that ended with "Unable to determine upstream SVN information from working tree history."
I guess this guy had the same problem, but he got no answers. Any ideas on how to do this?
edit:
I did some additional fiddling, but to no avail. I grafted git history onto svn history and did rebase, but it did not fix the problem. Strange. Here is what I did.
After git svn init
I did:
git svn fetch # so now I see the svn history in my git repo - I have two unconnected histories in my repo
git checkout svn-git #checking out svn remote
git checkout -b voracle_svn # putting content of the remote to a branch
Then in gitk I created branch named "graft_child" pointing to my initial git commit (start of my git history) and grafted that onto HEAD of svn branch:
git checkout graft_child # checking out the start of git repo
git reset --mixed voracle_svn #positioning myself to the HEAD of svn remote
git commit -am "Grafting git repo onto svn" #as the message said
Then I added SHA1 IDs of child and parent commits to .git/info/grafts and restarted gitk. Gitk now shows a single history (albeit with messed up dates), graft was successful. I then rebased the svn branch:
git checkout voracle_svn # checking out the branch which points to the HEAD of svn repo
git rebase master
This successfully Fast-forwarded voracle_svn to master, which means I should be able to push my repo to SVN. Or so I thought, because
git svn rebase
again gave me "Unable to determine upstream SVN information from working tree history."
Now I'm really out of ideas.
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.
Git installation comes with “git svn”. This will allow you to clone a SVN repository and provide a git interface over it. You can clone from a SVN repo using the git svn clone command. -s = If your SVN repo follows standard naming convention where main source is in “trunk”, branches are created in “branches”.
SVN is better than Git for architecture performance, binary files, and usability. And it may be better for access control and auditability, based on your needs.
Short Answer
You should init this svn repo with some commit by svn client first, like this.
$ touch foobar
$ svn add foobar
$ svn ci -m "init svn repo for git svn can detect upstream"
Long Answer
if svn repo is empty when you git svn clone xxx
, git client can't detect the upstream svn information from your working tree history, so you should init your svn repo like above.
Let us suppose your local git repo path is /path/to/git_work_tree
, your svn repo url is http://path/to/svn_remote_url
.
init svn repo by svn client.
$ svn co http://path/to/svn_remote_url svn_work_tree
$ cd /path/to/svn_work_tree
$ touch foobar
$ svn add foobar
$ svn ci -m "init svn repo"
git svn clone your svn repo to local.
$ git svn clone http://path/to/svn_remote_url git_svn_work_tree
merge your local git repo to git_svn_worktree
$ cd /path/to/git_svn_work_tree
$ git pull /path/to/git_work_tree
now you finally can commit your code
$ cd /path/to/git_svn_worktree
$ git svn rebase
$ git svn dcommit
HAVE FUN!
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