简体   繁体   English

将Subversion仓库的一部分转换为git

[英]Converting part of a subversion repo to git

First of all let me say: I've got a pretty rounded knowledge of git, but only a basic understanding of subversion. 首先让我说:我对git有相当全面的了解,但对Subversion却只有一个基本的了解。 Right: I have been tasked with porting a subversion repo to git. 正确:我的任务是将Subversion版本库移植到git。 The challenge is that i don't need the nested project, but rather i need to seperate out a folder further down, and create a new git repository from that. 挑战在于,我不需要嵌套项目,而是需要进一步分离出一个文件夹,然后从中创建一个新的git存储库。

The structure of the subversion repo is as follows: 颠覆存储库的结构如下:

http://path/to/repo/
->project1
->project2
  ->tags
    ->path/to/targetProject
  ->branches
    ->path/to/targetProject
  ->trunk
    ->path/to/targetProject

What is want is to create a new git repository that only includes the folder "targetProject" of project2. 想要创建一个仅包含project2的文件夹“ targetProject”的新git存储库。 I have been messing around with svn2git and git-svn, but so far i have only seen options to migrate the entire project2 structure. 我一直在搞混svn2git和git-svn,但是到目前为止,我只看到了迁移整个project2结构的选项。

The solution is located on that link: http://svnbook.red-bean.com/en/1.7/svn.ref.svndumpfilter.html 解决方案位于该链接上: http : //svnbook.red-bean.com/zh/1.7/svn.ref.svndumpfilter.html

It's about using svndumpfilter, that builds a dump of your full dumped repository that contains only the filtered ones, one example that solves your question is the next: 这是关于使用svndumpfilter的信息,它会构建完整转储的存储库的转储,其中仅包含已过滤的存储库,下一个示例解决了您的问题:

$svndumpfilter include --targets FILE < fullDumpfile > filteredDumpFile

Where the content of the 'FILE' is: “文件”的内容为:

/project2
/tags/path/to/project
/branches/path/to/project
/trunk/path/to/project

To obtain your first dumpfile, you have to run the next command (supposing you're on the svn server) 要获取第一个转储文件,您必须运行下一个命令(假设您在svn服务器上)

$svn dump --bypass-prop-validation -q path/to/your/repo > fullDumpFile.dmp

If you moved projects inside the starting svn probably you will have a little problems on your filter cause of dependencies. 如果您将项目移至起始svn内,则可能会导致过滤器的依赖性产生一些问题。

Just use git-svn, you can specify which svn dir contains trunk in case svn repo does not use standard layout: 只需使用git-svn,您可以指定哪个svn目录包含中继,以防svn回购不使用标准布局:

git svn init <url> --trunk=project2/trunk/path/to/targetProject
git svn fetch

It's neatly explained in git-svn man page . git-svn手册页中进行了巧妙地解释。

[edit] Since svn does not have notion of tags or branches (only "copies"), then in your case you won't be able to automatically convert them to git (because there is no svn dir, that contains copies of targetProject dir). [edit]由于svn没有标签或分支的概念(仅“副本”),因此在您的情况下,您将无法自动将它们转换为git(因为没有svn目录,其中包含targetProject目录的副本)。 But you can work around this by treating selected svn dirs as branches of targetProject. 但是您可以通过将选定的svn dirs视为targetProject的分支来解决此问题。 After initial fetch is finished, add following line to your .git/config for each branch, that you want: 初始提取完成后,将以下行添加到您想要的每个分支的.git / config中:

branches = project2/branches/{<branch_name>}/path/to/targetProject:refs/remotes/*

So in the end, section will look like this: 因此,最后,部分将如下所示:

[svn-remote "svn"]
    url = https://repo-url
    fetch=project2/trunk/path/to/targetProject
    branches = project2/branches/{branch_one}/path/to/targetProject:refs/remotes/*
    branches = project2/branches/{branch_two}/path/to/targetProject:refs/remotes/*

And do git svn fetch after that. 然后执行git svn fetch。

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

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