Svn只有一个子目录的Git [英] Svn to Git of only one subdirectory

查看:96
本文介绍了Svn只有一个子目录的Git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道git-svn,并用它将SVN存储库迁移到Git中。

有了一个回购协议,我有一个具体的要求,我找不到解决方案。该SVN回购包含多个实际项目作为子目录:

  trunk / 
project1 /
project2 /
project3 /
branches /
branch1 /
project1 /
project3 /
project2 /
...

等等...



我想要做的是将每个这些子项目自己在git中进行回购 - 显然,保留修订历史记录,分支,提交消息,标记等。

我可以使用 - ignore-paths --include-paths 一次只能切换其中一个子项目,但它们会仍然出现在相应的 project1 等子目录下。我真正想要结束的是每个分支(包括trunk)中的项目的内容。



有没有办法做到这一点?

解决方案

我找到了解决方案。它并不像 git svn clone 那么简单,但并不难。所以,这就是我所做的(例如,对于问题场景中的 project1 ):


  1. 在git服务器上为 project1

  2. 创建一个空的repo将空的repo克隆到本地机器上:

    git clone git@git.server.com:group / project1.git

  3. 进入该空白回购工作目录:

    cd project1

  4. 初始git svn回购:

    git svn init --stdlayout --no-metadata https://svn.server.com/group

  5. 现在,这里是魔术来了。如果此时我运行 git config --local --list ,我会得到以下内容(仅显示相关行):

      svn-remote.svn.fetch = trunk:refs / remotes / trunk 
    svn-remote.svn.branches = branches / *:refs / remotes / branches / *
    svn-remote.svn.tags = tags / *:refs / remotes / tags / *

    现在我需要做的只是在 git config --local --edit 中添加 project1 正确的地方:

      svn-remote.svn.fetch = trunk / project1:refs / remotes / trunk 
    svn- remote.svn.branches = branches / * / project1:refs / remotes / branches / *
    svn-remote.svn.tags = tags / * / project1:refs / remotes / tags / *


  6. 现在您可以 git svn fetch


  7. 设置分支和标签:

     用于`git branch中的分支-r | grepbranches /| sed's / branches\ ///'`;做
    git分支$分支refs /远程/分支/ $分支
    完成

    在`git branch中标记-r | greptags /| sed's / tags\ ///'`;做
    git标签-a -m转换SVN标签$ tag refs / remotes / tags / $ tag
    done


  8. 最后将其全部推送到远程:

      git push  - 所有来源
    git push - 标签来源


现在如果你克隆你的repo,你会在你的克隆的repo的根目录下得到 project1 的内容 - 正是我在找的东西。


I know about git-svn and have used it to migrate SVN repositories into Git.

With one repo I have a specific requirement, which I can't find a solution for. That SVN repo contains multiple actual projects as subdirectories:

trunk/
    project1/
    project2/
    project3/
branches/
    branch1/
        project1/
        project3/
        project2/
...

and so on...

What I want to do is import each of these "sub-projects" in its own repo in git - obviously, keeping revision history, branches, commit messages, tags, etc.

I can use --ignore-paths and --include-paths switches to only pull one of these sub-projects at a time, but they will still appear under the respective project1, etc. subdirectories. What I really want to end up with is the content of project being in the root in each branch (including trunk).

Is there a way to do this?

解决方案

I found the solution. It's not as simple as git svn clone, but not too difficult. So, here's what I did (say, for project1 in the scenario from the question):

  1. Create an empty repo on the git server for project1
  2. Clone the empty repo onto my local machine:
    git clone git@git.server.com:group/project1.git
  3. Go into that empty repo working directory:
    cd project1
  4. Init git svn repo:
    git svn init --stdlayout --no-metadata https://svn.server.com/group
  5. Now, here's where the magic comes. If at this point I run git config --local --list, I get the following (only relevant lines shown):

    svn-remote.svn.fetch=trunk:refs/remotes/trunk
    svn-remote.svn.branches=branches/*:refs/remotes/branches/*
    svn-remote.svn.tags=tags/*:refs/remotes/tags/*
    

    All that I need to do now is git config --local --edit and add project1 in the correct places:

    svn-remote.svn.fetch=trunk/project1:refs/remotes/trunk
    svn-remote.svn.branches=branches/*/project1:refs/remotes/branches/*
    svn-remote.svn.tags=tags/*/project1:refs/remotes/tags/*
    

  6. Now you can git svn fetch

  7. Set branches and tags:

    for branch in `git branch -r | grep "branches/" | sed 's/ branches\///'`; do
        git branch $branch refs/remotes/branches/$branch
    done
    
    for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do
        git tag -a -m"Converting SVN tags" $tag refs/remotes/tags/$tag
    done
    

  8. And finally push it all to the remote:

    git push --all origin
    git push --tags origin
    

Now if you clone your repo, you'll get the content of project1 in the root of your cloned repo - exactly what I was looking for.

这篇关于Svn只有一个子目录的Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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