如何在不丢失提交历史记录的情况下将代码从 SVN 迁移到 GIT?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9211405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:56:59  来源:igfitidea点击:

How to migrate code from SVN to GIT without losing commits history?

gitsvnversion-controlgit-svn

提问by simo

I would like to know the recommended way to move our code from a SVN repository to a GIT repository, so that we transition our developers team & start using GIT.

我想知道将我们的代码从 SVN 存储库移动到 GIT 存储库的推荐方法,以便我们转换我们的开发团队并开始使用 GIT。

Can we do the transition and keep all the commits done in the SVN repository ?

我们可以进行转换并将所有提交保留在 SVN 存储库中吗?

Also, our team is happy with SVN currently, but, they don't know that branching in GIT is much easier than SVN, where can I find a practical example that proves power of GIT in branching ?

另外,我们的团队目前对 SVN 很满意,但是,他们不知道在 GIT 中分支比在 SVN 中容易得多,我在哪里可以找到一个实际示例来证明 GIT 在分支中的强大功能?

采纳答案by J. C. Salomon

Eric Raymond (esr) has created reposurgeon, “a command interpreter for performing tricky editing operations on version-control histories.” The tool includes scripts for various purposes, including cleaning up the results of VCS conversions. Check it out from https://gitlab.com/esr/reposurgeon.

Eric Raymond (esr) 创建了reposurgeon,“一个用于对版本控制历史执行棘手编辑操作的命令解释器。” 该工具包括用于各种目的的脚本,包括清理 VCS 转换的结果。从https://gitlab.com/esr/reposurgeon查看。

As of version 2.0 it includes support for reading SVN dumpfiles for complete and idiomatic translation to Git, Mercurial, etc.; see http://esr.ibiblio.org/?p=4071for details. Reposurgeon has been used to convert several large projects to Git, including Emacs whose repository, ESR says, “is large, complex in branch structure, and old enough to have begun life as a CVS repo. That last part matters because some of the ugliest translation problems lurking in the back history of Subversion projects are strange Subversion operation sequences (including combinations of branch copy operations) generated by cvs2svn.”

从 2.0 版本开始,它支持读取 SVN 转储文件,以完整地、惯用地转换为 Git、Mercurial;有关详细信息,请参阅http://esr.ibiblio.org/?p=4071。Reposurgeon 已被用于将几个大型项目转换为 Git,包括 Emacs,其存储库,ESR 说,“庞大,分支结构复杂,并且足够老,已经开始作为 CVS 存储库。最后一部分很重要,因为潜伏在 Subversion 项目历史中的一些最丑陋的翻译问题是由 cvs2svn 生成的奇怪的 Subversion 操作序列(包括分支复制操作的组合)。”

(The git-svn tool included with Git will handle many Subversion repositories, including branches. It's pretty commonly used, especially by teams that are in the process of doing a conversion, since it allows Git to behave as a Subversion client. But see ESR's Don't do svn-to-git repository conversions with git-svn!, where he discusses the drawbacks to git-svn as a conversion tool.)

(Git 附带的 git-svn 工具将处理许多 Subversion 存储库,包括分支。它非常常用,尤其是在进行转换的团队中,因为它允许 Git 充当 Subversion 客户端。但请参阅 ESR不要使用 git-svn! 进行 svn 到 git 存储库转换,他在那里讨论了 git-svn 作为转换工具的缺点。)

Regarding your second question, it isn't branching where the power of Git is so helpful (though Git is at least as powerful as Subversion in this regard); it's when it comes to mergingthose branches that Git shines. Read through the Git Community Book, especially the section in chapter 3 titled “Basic Branching and Merging” and the section in chapter 7 titled “Advanced Merging”.

关于你的第二个问题,它并没有在 Git 的力量如此有用的地方进行分支(尽管在这方面 Git 至少与 Subversion 一样强大);当合并这些分支时,Git 会发光。通读Git 社区手册,尤其是第 3 章中标题为“基本分支和合并”的部分和第 7 章中标题为“高级合并”的部分。

回答by l0b0

Since there are already lots of people working with git-svn, I'd say it's very much possible. The following command is pretty well known:

由于已经有很多人在使用git-svn,我认为这是非常有可能的。以下命令是众所周知的:

git svn clone -s http://svn/repo

According to the manual(verified locally), this will keep the "trunk, tags and branches".

根据手册(在本地验证),这将保留“主干、标签和分支”。

回答by Nate

Update Apr 2014

2014 年 4 月更新

There is a tool called Svn2Gitthat does a pretty good job of making this process a bit easier. The documentation on the Github project is pretty good. (Ruby required)

有一个名为Svn2Git的工具可以很好地使这个过程变得更容易一些。Github 项目的文档非常好。(需要红宝石

It's worth noting that while git-svn defaults to pulling from just the path you specify, not branches, tags and trunk. Svn2git is the opposite. It will default to looking for a trunk, branches and tags under the path and you should use --nobranchesor --notagsto tell it not to search for those (though this may nullify the advantages of svn2git).

值得注意的是,虽然 git-svn 默认只从您指定的路径中拉取,而不是从分支、标签和主干拉取。Svn2git 正好相反。它将默认查找路径下的主干、分支和标签,您应该使用--nobranches--notags告诉它不要搜索这些(尽管这可能会抵消 svn2git 的优势)。



Once you move to Git, I suggest you move everyone and stay using Git. It's more complicated but the transition will be worth it. Github.com supports accessing the repo using an Subversion client (but you may loose the power of Git branching) and that might be a good stop-gap.

一旦你转移到 Git,我建议你转移所有人并继续使用 Git。它更复杂,但过渡将是值得的。Github.com 支持使用 Subversion 客户端访问存储库(但您可能会失去 Git 分支的功能),这可能是一个很好的权宜之计。

Can I keep my Subversion repo?

我可以保留我的 Subversion 存储库吗?

When you use the below method to move, all the current commits will remain in the Subversion repo. You may be able to do a one-way sync from the Subversion repo to the Git repo, but going the other way gets very complicated very fast. I would not recommend trying to sync either way and just move everyone one-time.

当您使用以下方法移动时,所有当前提交都将保留在 Subversion 存储库中。您也许可以从 Subversion 存储库到 Git 存储库进行单向同步,但以另一种方式快速同步会变得非常复杂。我不建议尝试以任何一种方式进行同步,而只是一次移动每个人。

What's powerful about Git?

Git 有什么强大的地方?

Git branching is powerful but it's not all there is to Git. Having a complete history locally means you can do everything you can do with Subversion, but without having to contact the server. Reviewing and searching the history, undoing changes, committing locally, branching locally become immensely faster. Git also compresses it's data, so a Subversion checkout (that includes only the latest revision) ends up being about the same size as a Git checkout (that includes the full history). Also, because data is compressed when transferred, pushing and pulling are much faster as well. Don't just push Git branches, put everything about Git.

Git 分支功能强大,但它并不是 Git 的全部。在本地拥有完整的历史记录意味着您可以使用 Subversion 执行您可以执行的所有操作,而无需联系服务器。查看和搜索历史、撤消更改、本地提交、本地分支变得非常快。Git 还会压缩它的数据,因此 Subversion 检出(仅包括最新修订版)最终与 Git 检出(包括完整历史记录)的大小大致相同。此外,因为数据在传输时被压缩,推和拉也快得多。不要只推送 Git 分支,把关于 Git 的一切都放上来。

How to move a repo using the git svnmethod.

如何使用git svn方法移动 repo 。

First, clone the Subversion repo. This might take a while.

首先,克隆 Subversion 存储库。这可能需要一段时间。

git svn clone http://www.example.com/svn-repo/projectA/trunk/

Where http://www.example.com/svn-repo/is the URL to the Subversion repo and projectA/trunk/is the path you want to copy into Git.

http://www.example.com/svn-repo/Subversion 存储库的 URL在哪里,是projectA/trunk/您要复制到 Git 中的路径。

If you have a standard layout such as projectA/trunk, projectA/branches/and projectA/tags/than you can add --stdlayoutand clone from a directory up like this

如果您有一个标准布局,例如projectA/trunk,projectA/branches/然后projectA/tags/您可以--stdlayout像这样从目录中添加和克隆

git svn clone --stdlayout http://www.example.com/svn-repo/projectA/  projectA.git-svn

And, if you have a trunk, branches and tags folder named differently then above, you an give git svn clonecustom names for each.

而且,如果您有一个与上面不同的主干、分支和标签文件夹,您可以git svn clone为每个文件夹指定自定义名称。

git svn clone --trunk my-trunk --branches my-branches --tags my-tags http://www.example.com/svn-repo/projectA/  projectA.git-svn

Once that completes all you have to do is push to the remote git repo with --mirror.

一旦完成,您所要做的就是使用 .git 推送到远程 git 存储库--mirror

cd projectA.git-svn
git push --mirror [email protected]:Account/projectA.git

At this point you should make your Subversion repo read-only to keep people from trying to commit to an out dated location.

此时,您应该将您的 Subversion 存储库设为只读,以防止人们尝试提交到过时的位置。

回答by eckes

The repo could be converted fully, including tags and all branches using git svn clone.

repo 可以完全转换,包括标签和所有使用git svn clone.

There's some tweaking neccesary to get the tags correct, see this linkfor more information.

需要进行一些调整才能使标签正确,请参阅此链接以获取更多信息。

This topic has been covered here at SO at least once before:
How to import svn branches and tags into git-svn?

之前在 SO 上至少介绍过一次该主题:
如何将 svn 分支和标签导入 git-svn?

回答by Alexander Kitaev

Safe and smooth migration approach from Svn to Git is to use SubGit- server-side Git/Svn synchronization tool. One may install SubGit into Subversion repository and continue to use both Subversion and Git simultaneously as long as migration process lasts.

从 Svn 到 Git 的安全平滑迁移方法是使用SubGit- 服务器端 Git/Svn 同步工具。只要迁移过程持续,您可以将 SubGit 安装到 Subversion 存储库中并继续同时使用 Subversion 和 Git。

Disclaimer: I'm SubGit developer who happily uses SubGit for half a year already.

免责声明:我是 SubGit 开发人员,已经愉快地使用 SubGit 半年了。

回答by Chris Maes

John Albin wrote some good scripts hereand herethat will do the whole conversion for you (including author conversion). The scripts are not perfect (I had some hickups with multiple branches and especially with svn externals).

John Albin在这里这里写了一些很好的脚本,它们将为您完成整个转换(包括作者转换)。脚本并不完美(我有一些关于多个分支的问题,尤其是 svn externals)。

Atlassian actually wrote a guideon the svn to git migration (and they have good tutorials on those pages too).

Atlassian 实际上写了一个关于 svn 到 git 迁移的指南(他们在这些页面上也有很好的教程)。

git is very powerfull but there is one caveat: up till now git doens't have anything so easy as svn:externals. There are alternatives (git subtree and git submodules) but they never work as intuitively as svn externals (but that is for another question: look around on stackoverflow you will find many questions related to this topic)

git 非常强大,但有一个警告:到目前为止,git 没有像 svn:externals 那样简单的东西。有替代方案(git subtree 和 git submodules),但它们从来没有像 svn externals 那样直观(但这是另一个问题:环顾 stackoverflow,您会发现许多与此主题相关的问题)

回答by Thorbj?rn Ravn Andersen

I migrated our CVS repository a while back to git, by first converting to subversion and then to git. This worked well when using the right tooling for it.

我将我们的 CVS 存储库迁移回了 git,首先转换为 subversion,然后转换为 git。当使用正确的工具时,这很有效。

See Most robust way to convert a CVS repository containing Eclipse projects to git?

请参阅将包含 Eclipse 项目的 CVS 存储库转换为 git 的最可靠方法?

Also, when done, test rigoriously.

此外,完成后,请严格测试。

Regarding git branching, that is not the smart part. The advantage come when you need to mergebranches.

关于 git 分支,这不是聪明的部分。当您需要合并分支时,优势就来了。