简体   繁体   English

将现有的Git仓库推送到svn中的文件夹

[英]Push existing Git repo to a folder in svn

I have an existing git repository in which I've always been working on. 我有一个现有的git存储库,我一直在努力。 But recently, I'd need to push the commits into svn (no need to include all the merge, but at least a single linear master branch will do) 但是最近,我需要将提交推送到svn(不需要包含所有合并,但至少有一个线性主分支可以)

I'm not very good in git/svn, I'm just a general user that use SourceTree and CornerStone or Tortoise with nice UI to do my commits, branching and tagging. 我不是很擅长git / svn,我只是一个普通的用户,使用SourceTree和CornerStone或者Tortoise,有很好的用户界面来做我的提交,分支和标记。 I've used git-svn before to migrate an svn repo into git, but never did the vice versa. 我之前使用git-svn将svn repo迁移到git中,但从来没有反之亦然。

Is it possible? 可能吗? I've googled through several tutorials but none of them work. 我已经通过几个教程搜索,但没有一个工作。 I'm also not very good with those terms like rebase , reflog etc and will be very appreciative if there is some good guide to get the simple things done without needing to learn through the more complex part of git/svn. 我也不太喜欢rebasereflog等术语,如果有一些很好的指导来完成简单的事情而不需要通过git / svn更复杂的部分来学习,我将非常感激。 (Simple as I guess there must be people who're facing the same problem and did it before) (简单,因为我猜必须有人面对同样的问题并且之前做过)

Thanks in advance! 提前致谢!

Well, it is actually quite simple.. first you need to clone your svn through git, then add the git repo as another remote to it. 好吧,它实际上很简单..首先你需要通过git克隆你的svn,然后将git repo添加为另一个遥控器。 This will give you two separate HEAD , that's why you need to git-rebase your git commits into the git-svn head. 这将给你两个单独的HEAD ,这就是为什么你需要git-rebase你的git提交到git-svn头。 There may be conflicts though as svn only has linear commits. 可能存在冲突,因为svn只有线性提交。 This is why you need the various git command to fix all those before you finally git svn dcommit to push everything into the svn. 这就是为什么你需要各种git命令来修复所有这些之前你最终git svn dcommit将所有内容都推送到svn。

Here is the summary: 以下是摘要:

1. Create a git svn clone tracking svn 1.创建一个git svn clone tracking svn

git svn clone svn://DEST/repo/projectname/trunk dest

Now we have a git repo that tracks the destination svn landing point for the import operation. 现在我们有一个git repo跟踪导入操作的目标svn登陆点。

2: Track the git repo we want to import 2:跟踪我们要导入的git仓库

cd dest
git remote add -f source /path/to/git/source/repo

Now, if you inspect the git history, you'll see a whole series of commits from the original git repo and, disconnected from this, the master HEAD plus a git-svn HEAD pointing to the original (single) svn commit we cloned. 现在,如果您检查git历史记录,您将看到来自原始git repo的一系列提交,并且与此断开连接,主HEAD加上指向我们克隆的原始(单个)svn提交的git-svn HEAD。

3: Rebase the original git repo onto git-svn 3:将原始git repo重新基于git-svn

Here's where the secret magic lies. 这就是秘密魔法的所在。 I seems like there are many ways to go from here. 我似乎有很多方法可以从这里开始。 This was the only one I found to work. 这是我发现的唯一一个工作。 Of course, I tried many ways that failed. 当然,我尝试了许多失败的方法。 Once I found one that worked, I stopped trying. 一旦我发现一个有效,我就停止了尝试。 So if there's a better way I'd love to hear it, but this seems to work well. 所以如果有更好的方式我会喜欢听,但这似乎运作良好。

git rebase --onto remotes/git-svn --root source/master

At this point, I realised that my git history wasn't strictly linear; 在这一点上,我意识到我的git历史不是严格线性的; I had worked on a few machines, so the history of trunk wove arond a bit. 我曾经在几台机器上工作过,所以后备箱的历史有点像。

This meant that what I had expected to be a straightforward operation (that's what you'd expect with a SVN hat on) required a few rebase fix-ups along the way: 这意味着我所期望的是一个简单的操作(这是你对SVN帽子所期望的),需要一些修改:

(
gvim foo # fix merge conflict
git add foo
git rebase --continue
)
# ... rinse and repeat

These were required because branches in the source repo from work on different machines that got merged together to form the "source" trunk line of development didn't flatten into a rebase without a few tweaks. 这些都是必需的,因为在不同机器上工作的源代码中的分支被合并在一起形成“源”主干开发线,并没有在没有一些调整的情况下变成一个rebase。

In general, the conflicts were small and weren't hard to fix. 总的来说,冲突很小,并不难解决。

4: Push up to svn 4:向上推到svn

Now that we've arranged everything above git-svn, it's a simple case of: 现在我们已经安排了git-svn以上的所有内容,这是一个简单的例子:

git svn dcommit

To push the changes up into svn. 将更改推送到svn。

Source: http://goodliffe.blogspot.sg/2011/08/pushing-git-repository-into-existing.html 资料来源: http//goodliffe.blogspot.sg/2011/08/pushing-git-repository-into-existing.html

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

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