SVN 到 Git 迁移:只导入某些分支和历史记录 [英] SVN to Git migration: Only import certain branches and history

查看:34
本文介绍了SVN 到 Git 迁移:只导入某些分支和历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队正准备迁移到 Git,我们希望从一个小型存储库开始.由于二进制文件和数百个版本分支,git-svn 创建的初始 Git 存储库大约为 10GB.

My team is preparing to migrate to Git and we'd like to start with a small repository. The initial Git repository created by git-svn is about 10GB large due to binary files and hundreds of version branches.

清理大文件很容易,棘手的部分似乎是分支的数量.

Cleaning big files out is easy, the tricky part seems to be the number of branches.

对于 git 迁移,我们希望从某个时间点 (X) 开始,只有某些(最新的)分支.我们没有主干"——而是在较长时间内维护的不同版本分支:

For the git migration, we'd like to start at a certain point in time (X) with only certain (the newest) branches. We do not have a "trunk" - but instead different version branches that are maintained over a longer time period:

 ---- Version 1 ------------------------
     \---------- Version 2--------------
                \--------- Version 3----

我很容易地发现了如何从历史记录中清除大块(BFG、git filter-branch).

I easily found out how to clean big blobs from the history (BFG, git filter-branch).

我的问题:

我们如何删除除少数特定分支之外的所有分支从历史记录,以便我们在新的存储库中只有分支版本 3"?理想情况下,我们希望历史从创建此分支的开始提交开始:

How can we remove all branches except a few specific ones from history so that we only have, say, branch "version 3" in the fresh repository? Ideally, we'd like the history to begin at the start commit where this branch was created:

 --------- Version 3----

有没有办法用 git filter-branch 或其他方法来做到这一点?

Is there a way to do this with git filter-branch or another possibility?

推荐答案

将整个仓库导入 Git,然后把你不感兴趣的分支扔掉.

Import the whole repository into Git, and then throw away the branches you are not interested in.

丢弃部分将是有趣的部分 :D 我们如何将它们丢弃并从回购历史中根除它们?

The throw away part would be the interesting one :D How can we throw them away and eradicate them from the repo history?

好吧,按照 Git 的工作方式,分支只是指向存储库历史记录中提交的指针.分支的存在是因为存在那些指向它们的指针.如果删除指针,分支就会消失.如果没有其他内容指向这些提交,则这些提交基本上会从存储库中删除.

Well, the way Git works, branches are just pointers to commits within the history of the repository. Branches exist because those pointers exist to point to them. If you remove the pointers, the branches just disappear. And if nothing else points to those commits, the commits are essentially removed from the repository.

现在除了分支,还有另一个突出的东西通常指向提交并保持周围:新的提交取决于它们.Git 的历史是一棵大的非循环树,其中每个提交都有它指向的父提交.这样,即使没有分支明确指向它们,旧的提交也会保留下来;如此一来,整个历史就开始运作了.

Now beside branches, there is another prominent thing that usually points at commits and keeps the around: Newer commits depending on them. Git’s history is a large acyclic tree in which each commit has parent commits it points to. By that, the old commits stay around even when no branch is explicitely pointing at them; and by that, the whole history works.

因此,如果您想删除一整行提交(一个单独的分支),并且这些提交在某个时候没有合并到另一个分支中,那么您需要做的就是从存储库中删除该分支.然后,没有任何内容指向提交行,当您对存储库进行垃圾收集时,它们将被删除:

So if you want to get rid of a whole line of commits (a separate branch), and those commits were not merged into another branch at some point, then all you need to do is remove the branch from the repository. Then, nothing will point to the line of commits and they will be removed when you garbage-collect the repository:

git branch -D Version_1
git branch -D Version_2
git gc --prune=now

这将强制删除存储库中的分支 Version_1Version_2,然后运行垃圾收集,从存储库中删除没有指向它的指针的每个对象.

This will force-delete branches Version_1 and Version_2 from the repository, and afterwards run the garbage collection that removes every object from the repository which has no pointer pointing to it.

之后,您将拥有 Version_3 的完整历史记录,包括属于其历史记录一部分的其他两个版本的那些部分.如果您也想删除它,您可以应用 这个问题 删除版本3分支点之前的旧历史

Afterwards, you have the full history left for Version_3, including those parts from the other two versions that are part of its history. If you want to remove that as well, you can apply the method explained in this question to remove the old history before the branch point of version 3.

这篇关于SVN 到 Git 迁移:只导入某些分支和历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆