简体   繁体   English

将特定SVN分支迁移到GIT(2018年迁移的trunk)

[英]Migrating specific SVN branches to GIT (trunk migrated in 2018)

I have a SVN repo that sometime during 2018 was partially migrated to GIT (Bitbucket).我有一个 SVN 存储库,它在 2018 年的某个时候部分迁移到了 GIT(Bitbucket)。 Both the SVN and GIT repos are in use. SVN 和 GIT 存储库都在使用中。 On SVN side mostly branches for older projects.在 SVN 方面,主要是旧项目的分支。 The GIT repo was used for trunk/master development. GIT 存储库用于主干/主开发。 Now I'm being asked to migrate the remaining branches from SVN to GIT.现在我被要求将剩余的分支从 SVN 迁移到 GIT。 The problem is I don't know how the original conversion was done exactly(the person who have done this left the company).问题是我不知道原始转换是如何完成的(完成此操作的人离开了公司)。 I can easily get the SVN repo converted to GIT but I can never get it in a state where the commit ids actually match.我可以轻松地将 SVN 存储库转换为 GIT,但我永远无法将其置于提交 ID 实际匹配的状态。 Currently the approach that gets me the closest seems to be目前让我最接近的方法似乎是

git svn clone -T trunk URL --no-minimize-url --no-metadata -r1:10 --preserve-empty-dirs 

I'm using the -r on only a few revisions so it's faster.我只在少数版本中使用 -r,所以速度更快。 The author actually gets same email (name@UUID) and the UUID matches the git repo converted in 2018. The problem seems to be that the SVN history starts with 2 commits that contain only folders and commit message - these commits are being ignored for me but somehow for the older migration they resulted in a git commit with just the message.作者实际上收到了相同的电子邮件(name@UUID)并且 UUID 与 2018 年转换的 git repo 匹配。问题似乎是 SVN 历史记录以 2 个仅包含文件夹和提交消息的提交开始 - 这些提交对我来说被忽略但不知何故,对于较旧的迁移,他们导致只包含消息的 git commit。

Example:例子:

svn SVN

commit A: create dir 1

commit B: create dir 2

commit C: create some files in dir 1 and 2

original git migration result:原始 git 迁移结果:

commit A: commit message only

commit B: commit message only

commit C: create some files in dir 1 and 2

my current efforts using git svn:我目前使用 git svn 所做的努力:

commit C: create some files in dir 1 and 2

attempt using SubGit:尝试使用 SubGit:

subgit import --trunk trunk --username user --svn-url URL)
commit A: commit message only (modified with notes)

commit B: commit message only (modified with notes)

commit C: create some files in dir 1 and 2 (commit message modified with notes)

notes on SubGit - this approach is pretty close (based on the documentation i'm pretty sure i can get the commit message fixed).关于 SubGit 的说明 - 这种方法非常接近(根据文档,我很确定我可以修复提交消息)。 The problem for me is that if I do not provide the authors file instead of ending up with 'user@uuid' I end up with 'user@localdomain'.我的问题是,如果我不提供作者文件而不是以“user@uuid”结尾,我会以“user@localdomain”结尾。 Possible workaround would be to provide export the authors from the original migration and provide this as authors file ?可能的解决方法是从原始迁移中导出作者并将其作为作者文件提供?

Anyone got any suggestions on how to do this ?有人对如何做到这一点有任何建议吗? If i cannot get to the same commit ids on git side is there some sane way of "merging" two git repos if I can find the common ancestor (even though id's don't match) ?如果我无法在 git 端获得相同的提交 id,如果我能找到共同的祖先(即使 id 不匹配),是否有某种“合并”两个 git repos 的理智方法?

您可能会考虑创建一个单独的 svn repo 克隆,从修订之前的修订开始,您这次要克隆的最旧分支开始,并且您只克隆您关心的分支......然后您可以将这些修订移到其他分支所在的另一个 git 仓库(使用补丁或使用可以访问两个 git 仓库作为远程的仓库)......如果您使用与基础相同的修订版,则 git 应用修订版应该没有任何问题这是从新克隆中出来的……我承认我过于简单化了,你可能会得到一些极端情况,但基本逻辑是合理的。

This is default SubGit's behavior -- if it's not given an author mapping (or in case if no match for an SVN username is found) then it generates a Git identity using the SVN user name and the default domain (which is set by core.defaultDomain SubGit configuration setting or default-domain command option).这是 SubGit 的默认行为——如果它没有给出作者映射(或者如果没有找到与 SVN 用户名匹配的情况),那么它会使用 SVN 用户名和默认域(由 core.conf 设置)生成一个 Git 身份。 defaultDomain SubGit 配置设置或default-domain命令选项)。 So if you need SubGit to set certain Git user identity for a given commit, then it's indeed better to provide it with an authors mapping file.因此,如果您需要 SubGit 为给定的提交设置某些 Git 用户身份,那么为它提供作者映射文件确实更好。 If can be done with the "authors-file" command option (which probably you know, but still :))如果可以使用“authors-file”命令选项完成(您可能知道,但仍然:))

subgit import --trunk trunk --username user --authors-file <AUTHORS_FILE_PATH> --svn-url URL

I didn't get completely what is wrong with the commit messages, assume that the commit messages in Git does not match those in SVN?我没有完全理解提交消息有什么问题,假设 Git 中的提交消息与 SVN 中的提交消息不匹配? If yes, then this can also be with SubGit, yet not with subgit import one-liner, it would require import with preliminary configuration and the configuration file editing.如果是,那么这也可以用SubGit,但不是用subgit import one-liner,它需要带初步配置和配置文件编辑导入。 So, first run the following command to prepare a Git repository for import:因此,首先运行以下命令来准备要导入的 Git 存储库:

subgit configure --snv-url URL <GIT_REPO>

where GIT_REPO is a path to the new Git repository for the import.其中 GIT_REPO 是用于导入的新 Git 存储库的路径。 After the repository is prepared, edit the GIT_REPO/subgit/config file, set core.defaultDomain and core.authorsFile if needed, set correct mapping in [svn] section and the configure desired commit message with the svn.gitCommitMessage setting, here are a little more details about this setting:准备好存储库后,编辑 GIT_REPO/subgit/config 文件,根据需要设置core.defaultDomaincore.authorsFile ,在[svn]部分设置正确的映射,并使用svn.gitCommitMessage设置配置所需的提交消息,这里有一个有关此设置的更多详细信息:

https://subgit.com/documentation/config-options.html#svn.gitCommitMessage https://subgit.com/documentation/config-options.html#svn.gitCommitMessage

after the configuration file is set, the import can be started with short command:配置文件设置好后,可以使用短命令启动导入:

subgit import GIT_REPO

As for the Git commit notes -- SubGit always creates the notes, but they don't affect commits SHA1, so no actions are needed for the notes.至于 Git 提交注释——SubGit 总是创建注释,但它们不会影响提交 SHA1,因此不需要对注释执行任何操作。 Note, by the way, that authors and commit messages are not the only setting that may affect commits SHA1, there are also settings like 'svn.excludePath` or 'translate.createEmptyGitCommits'.请注意,顺便说一下,作者和提交消息并不是唯一可能影响提交 SHA1 的设置,还有像“svn.excludePath”或“translate.createEmptyGitCommits”这样的设置。

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

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