如何将本地git存储库导入svn?

时间:2012-06-22 00:33:39

标签: git-svn

我正在使用本地git存储库,我需要将本地git推送到现有的 svn存储库。我的git存储库是纯本地git存储库,使用git svn clone init。

如何将此本地git repo导入svn?

最好是我想将git历史记录导入SVN。

目前SVN存储库的结构为:

https://svnrepohost
           /branches
           /tags
           /trunk
                  /projectA
                  /projectB
                  /newProject

我需要的是将我的git存储库导入上面的https://svnrepohost/trunk/newProject,假设newProject文件夹为空。

4 个答案:

答案 0 :(得分:28)

我终于通过以下步骤解决了这个问题:

  1. 在svn中设置要导入的相应项目文件夹,例如http://svnrepo/svn/trunk/newProject

  2. 创建一个新的git-svn存储库

      

    git svn clone http://svnrepo/svn/trunk/newProject

  3. 将我们要导入的git repo添加为 远程 new git-svn repo

      

    git remote add origin ../ original-git-repo

  4. 从original-git-repo

    中提取所有数据
      

    git pull origin master --allow-unrelated-histories

  5. 针对svn重新定位本地存储库

      

    git svn rebase

  6. 将更改提交到svn

      

    git svn dcommit

  7. 清理遥控器

      

    git remote delete origin

答案 1 :(得分:1)

最简单的方法是只在svn import Git目录。但是,这将失去你的Git提交历史。

首先,通过在Subversion配置文件中设置.git,确保不会导入global-ignores目录。打开您的~/.subversion/config文件(在Windows上类似于C:\Users\username\.subversion\config),找到以[miscellany]开头的部分,并在阅读下方直接添加一行,如下所示:

global-ignores = .git

(如果您已经有一行global-ignores =,前面没有#,那么只需将.git添加到该行的末尾。)

接下来,运行以下内容:

svn import <path-to-local-git-repository> https://svnrepohost/trunk/newProject

这应该将本地Git存储库的内容完全复制到服务器上。

答案 2 :(得分:0)

您可以使用SubGit

$ svnadmin create repo.svn
$ subgit configure repo.svn                                                                                                                                                              

...                                                                                                                                                                           

            CONFIGURATION SUCCESSFUL                                                                                                                                                                                   

            Adjust '/tmp/repo.svn/conf/subgit.conf' file                                                                                                                                                               
            and then run                                                                                                                                                                                               
                subgit install "repo.svn"                                                                                                                                                                              
            to complete SubGit installation.
$ nano repo.svn/conf/subgit.conf #edit to set git.default.repository=path/to/your/bare/git/repository
$ subgit install repo.svn

我还建议您创建Git存储库的裸克隆并指定它的路径(在git.default.repository中)而不是原始存储库。即。

$ git clone --bare path/to/your/original/repository path/to/your/bare/git/repository

在“subgit install”命令之后,存储库(repo.svn和repo.git)将处于连续同步状态(由Git中的预接收挂钩触发[从推送到裸存储库开始]并在SVN中预先提交)。要停止同步,您可以运行

$ subgit uninstall repo.svn

答案 3 :(得分:0)

  • git svn clone http://svnrepo/svn/trunk/newProject
  • git remote add origin ../ original-git-repo
  • git fetch origin
  • git checkout -b lmaster remotes / origin / master
  • git rebase master
  • git svn rebase
  • git svn dcommit
相关问题