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

标签 git git-svn

我有一个 git 存储库,我的公司分配给我一个空的 svn 存储库来存储我的代码。所以我想做的就是将该 svn 存储库作为远程添加到我现有的 git 存储库,然后推送到

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

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

我尝试简单地执行 git svn init http://remote-repo,然后执行 git svn rebase,但结果是“无法确定上游 SVN来自工作树历史的信息。”

我猜 this guy有同样的问题,但他没有得到答案。关于如何执行此操作的任何想法?

编辑:

我做了一些额外的摆弄,但无济于事。我将 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

然后在 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 仓库,就像这样。

$ 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 存储库路径是 /path/to/git_work_tree,您的 svn 存储库 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 $ 触摸 foobar $ svn 添加 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 仓库 merge 到 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

玩得开心!

关于git - 将 svn-remote 添加到现有的 git repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22527867/

相关文章:

git - 哪个提交有这个 Blob ?

git-svn - git svn dcommit 是原子的吗?

git - 无法使用 git-svn : Your file or directory is probably out of date 提交删除

Git - 'assume-unchanged' 和 'skip-worktree' 之间的区别

android - 我可以更改 Android Studio 中的默认 git 分支吗?

svn - 在仅跟踪主干的 git-svn 仓库上开始跟踪分支/标签

git-svn - 如何在Git-Svn存储库中更改前缀映射?

git - 致命的 : git-write-tree: error building trees

git - Android Studio 中的扩展提交描述消息

git - 构建包含多个 git 存储库的 eclipse 项目