繁体   English   中英

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

[英]Adding svn-remote to existing git repo

我有一个 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 history 嫁接到 svn history 上并做了 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

然后在 gitk 中,我创建了名为“graft_child”的分支,指向我的初始 git 提交(我的 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,这意味着我应该能够将我的 repo 推送到 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"

长答案

如果git svn clone xxx时 svn repo 为空,则 git 客户端无法从您的工作树历史记录中检测到上游 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 repo 克隆到本地。 $ git svn clone http://path/to/svn_remote_url git_svn_work_tree

  3. 将本地 git 仓库合并到 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

玩得开心!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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