将svn-remote添加到现有的git repo

迪克斯特拉

我有一个git repo,我的公司为我分配了一个空的svn repo来存储我的代码。因此,我想做的就是将svn repo添加为现有git repo的远程目录,然后推送到它。

现在,所有git-svn教程都从“首先克隆svn存储库,然后添加代码”开始。这对我不起作用,因为我已经有一个现有的git repo。

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

我试图先做一个git svn init http://remote-repo,然后git svn rebase,但是以“无法从工作树历史中确定上游SVN信息”结尾。

我猜这个人有同样的问题,但是他没有答案。有关如何执行此操作的任何想法?

编辑:

我做了一些额外的摆弄,但无济于事。我将git history移植到了svn历史上并进行了重新设置,但是并不能解决问题。奇怪的。这是我所做的。

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

然后在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

然后,我将子项和父项提交的SHA1 ID添加到.git / info / grafts并重新启动gitk。Gitk现在显示了一个单一的历史记录(尽管日期混乱),嫁接成功了。然后,我重新建立了svn分支的基础:

git checkout voracle_svn # checking out the branch which points to the HEAD of svn repo
git rebase master

这成功将voracle_svn快速转发到master,这意味着我应该能够将我的存储库推送到SVN。还是我想,因为

git svn rebase

再次给我“无法从工作树历史记录中确定上游SVN信息”。

现在我真的没主意了。

奥德曼

简短答案

您应该先通过svn客户端的一些提交来初始化此svn repo,如下所示。

$ touch foobar
$ svn add foobar
$ svn ci -m "init svn repo for git svn can detect upstream"

长答案

如果svn repo在您使用时为空git svn clone xxx,则git client无法从您的工作树历史记录中检测到上游svn信息,因此您应该像上面那样初始化svn repo。

让我们假设您的本地git repo路径是/path/to/git_work_tree,您的svn repo url是http://path/to/svn_remote_url

  1. svn客户端初始化svn repo。 $ 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将您的svn存储库克隆到本地。 $ git svn clone http://path/to/svn_remote_url git_svn_work_tree

  3. 合并您本地的git repo到git_svn_worktree $ cd /path/to/git_svn_work_tree $ git pull /path/to/git_work_tree

  4. 现在您终于可以提交您的代码 $ cd /path/to/git_svn_worktree $ git svn rebase $ git svn dcommit

玩得开心!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章