简体   繁体   中英

Adding svn-remote to existing git repo

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.

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 .

  1. 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"

  2. git svn clone your svn repo to local. $ git svn clone http://path/to/svn_remote_url git_svn_work_tree

  3. merge your local git repo to git_svn_worktree $ cd /path/to/git_svn_work_tree $ git pull /path/to/git_work_tree

  4. now you finally can commit your code $ cd /path/to/git_svn_worktree $ git svn rebase $ git svn dcommit

HAVE FUN!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM