将svn-remote添加到现有的git仓库

dij*_*tra 14 git git-svn

我有一个git repo,我的公司给我一个空的svn repo来存储我的代码.所以我想做的就是将svn repo添加为我现有的git repo的远程,然后推送到它.

现在,所有git-svn教程都以"首先克隆svn repo,然后添加代码"开头.这对我不起作用,因为我已经有了一个现有的git repo.

我还找到了一些将svn分支导入git repo的教程,但这也不是我需要的,我需要将git repo导入到svn repo中.

我试图简单地做一个git svn init http://remote-repo,然后git svn rebase,但结束时"无法确定工作树历史中的上游SVN信息."

我猜这家伙有同样的问题,但他没有答案.关于如何做到这一点的任何想法?

编辑:

我做了一些额外的打击,但无济于事.我把git历史嫁接到了svn历史并且做了rebase,但它没有解决问题.奇怪.这就是我做的.

之后git svn init我所做的:

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
Run Code Online (Sandbox Code Playgroud)

然后在gitk中我创建了一个名为"graft_child"的分支,指向我最初的git commit(我的git历史的开头)并将其移植到svn分支的HEAD上:

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
Run Code Online (Sandbox Code Playgroud)

然后我添加了孩子和父提交的SHA1 ID到.git/info/grafts和resetarted gitk.Gitk现在显示了单一的历史(尽管有混乱的日期),移植成功.然后我重新定义了svn分支:

git checkout voracle_svn # checking out the branch wich points to the HEAD of svn repo
git rebase master
Run Code Online (Sandbox Code Playgroud)

这成功快速转发voracle_svn到master,这意味着我应该能够将我的repo推送到SVN.或者我想,因为

git svn rebase
Run Code Online (Sandbox Code Playgroud)

再次给了我"无法确定工作树历史中的上游SVN信息."

现在我真的没有想法:-(

old*_*man 10

简答

你应该首先使用svn客户端的一些提交来初始化这个svn repo,就像这样.git svn clone xxx


答案很长

如果你的svn repo为空/path/to/git_work_tree,git客户端无法从你的工作树历史中检测到上游的svn信息,所以你应该像上面那样初始化你的svn repo.

让我们假设您的本地git repo路径是http://path/to/svn_remote_url,您的svn repo url是 $ 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".

  1. svn客户端的init svn repo. $ git svn clone http://path/to/svn_remote_url git_svn_work_tree

  2. git svn将你的svn repo克隆到本地. $ cd /path/to/git_svn_work_tree $ git pull /path/to/git_work_tree

  3. 将您当地的git repo合并到git_svn_worktree $ cd /path/to/git_svn_worktree $ git svn rebase $ git svn dcommit

  4. 现在你终于可以提交你的代码git svn clone xxx

玩得开心!