简体   繁体   English

如何修复SVN中向Git迁移的部分目录结构分支

[英]How to fix branches of partial directory structure in SVN to Git migration

I'm trying to convert an SVN repository containing a Java EE application into a Git repository. 我正在尝试将包含Java EE应用程序的SVN存储库转换为Git存储库。 The original repository contains a folder for each part of the Java EE project which has been maintained as separate projects history-wise. 原始存储库为Java EE项目的每个部分都包含一个文件夹,该文件夹在历史上一直作为单独的项目维护。 For two of the projects there's also a "production"-branch (again, two separate branches) and whenever a new revision goes into production trunk is merged up into production. 对于其中的两个项目,还有一个“生产”分支(同样,有两个独立的分支),每当新版本进入生产时,主干就会合并到生产中。

When I import this into one single git repository (as I understand would be best practice) everything in master is fine, but when I switch to a branch I only get the files of that branch and most of the other folders and files disappear. 当我将其导入一个单独的git存储库时(据我所知将是最佳实践),master上的所有内容都很好,但是当我切换到分支时,我只会得到该分支的文件,而其他大多数文件夹和文件都会消失。

Repository layout: 仓库布局:

/
trunk/
   project1/
   project2/
   project3/
   project4/
branches/
   project3-production-branch/
   project4-production-branch/
tags/

I found a post by Eric Gwin about this issue, but I couldn't see there was any solutions to it. 我找到了埃里克·格温(Eric Gwin)的一则有关该问题的文章,但我看不出有任何解决方案。 http://comments.gmane.org/gmane.comp.ide.eclipse.git/77 http://comments.gmane.org/gmane.comp.ide.eclipse.git/77

I might be overlooking something very elementary here, but I do fear that the only solution is to import the projects separetely? 我可能会忽略这里非常基本的内容,但我确实担心唯一的解决方案是分别导入项目? Any suggestions to how I can import the whole SVN-repo and get working branches in Git? 关于如何导入整个SVN-repo并在Git中获得工作分支的任何建议?

Initial situation 初始情况

After converting this to a single repository, the directory structure in master (or trunk) looks like this: 将其转换为单个存储库后,主服务器(或主干)中的目录结构如下所示:

project1/
project2/
project3/
project4/

The structure after the first commit of the project3-production-branch looks either like this: project3-production-branch的第一次提交之后的结构如下所示:

project3/

Or it contains the contents of project3 directly: 或者它直接包含project3的内容:

.project
src/
test/

This depends on where the branch was copied from in Subversion. 这取决于在Subversion中从何处复制分支。

In the first case, the next step can be skipped. 在第一种情况下,可以跳过下一步。

In both cases, all other projects were removed on the branch (you should see that in the diff of the first commit) and need to be restored, see second step. 在这两种情况下,所有其他项目都在分支上被删除(您应该在第一次提交的差异中看到它)并且需要恢复,请参见第二步。

Step 1: Rewrite branch to move all contents into subdirectory (if needed) 步骤1:重写分支以将所有内容移动到子目录(如果需要)

See example "To move the whole tree into a subdirectory" in filter-branch and execute that only on the branch, like so: 请参阅filter-branch中的示例“将整个树移到子目录中”,并仅在分支上执行,如下所示:

git filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&project3/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' \
     master..project3-production-branch

Step 2: Rewrite branch to restore other projects 步骤2:重写分支以还原其他项目

In this step we want to undo the removal of the other projects in the first branch commit. 在这一步中,我们要撤消对第一个分支提交中其他项目的删除。 This can be done using the following: 可以使用以下方法完成此操作:

branch="project3-production-branch"
parent=`git merge-base $branch master` # or replace master with trunk if needed
paths="project1 project2 project4"
git filter-branch -f --index-filter \
"git reset -q $parent -- $paths" --tag-name-filter cat -- \
$parent..$branch

It resets the other paths to the state they were in when the branch was created, for all commits from the branch. 对于分支中的所有提交,它将其他路径重置为创建分支时所处的状态。

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

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