我如何重新连接一个svn仓库的git仓库? [英] How can I reconnect a git repository with a svn repository?

查看:115
本文介绍了我如何重新连接一个svn仓库的git仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 git svn 将现有的Subversion仓库导入到git中。然后我把它推到了git服务器上的git repo。在过去几个月里,Subversion和git存储库都对软件进行了更改。



我试着用 git svn ,但是当我从git服务器执行pull操作时,它会抱怨警告:没有常见冲突,我最终将两个分离的分支合并为相同的提交在开始时。像这样:

  F 
| \
| \
E D
| |
C C
| |
B B
| |
AA

我该如何处理svn更改,就像他们在分支上发生的那样从原始回购?

  F 
| \
| \
E D
| /
| /
C
|
B
|
A


解决方案

默认 git-svn 存储SVN修订和提交消息中的Git提交之间的映射。你看到这些 git-svn-id 这行代表原始Git仓库中较旧的提交吗?这里我的意思是Git服务器托管的仓库,而不是 那个你最近从SVN获取的仓库。

如果是这样,你实际上没有丢失任何链接,git-svn应该能够从历史记录中恢复必要的数据。虽然由于不同版本的git-svn之间的一些兼容性问题,这可能有点棘手:


  1. 克隆原始Git存储库:

      $ git clone $ GIT_SERVER repo 
    $ cd repo


  2. 更新.git / config中的git-svn配置:

      $ git config svn-remote.svn.url $ SVN_URL 
    $ git config svn-remote.svn.fetch trunk:refs / remotes / trunk
    $ git config svn-remote.svn .branches branches / *:refs / remotes / *
    $ git config svn-remote.svn.tags tags / *:refs / remotes / tags / *
  3. 现在你必须更新refs / remotes / * refs到git-svn-id行的最新提交:

      $ git log --first-parent refs / heads / master 
    commit d566edf5f77ae0a2f7418c40949757e75ef8e83c
    D

    commit 4df9f21346526c6505a954d8310637864710308d
    C
    git-svn-id:$ SVN_URL ... / trunk @ 3 ...

    commit 116a6760d3e278aa4d54f5bb22e531d 30d731661
    B
    git-svn-id:$ SVN_URL ... / trunk @ 2 ...

    commit d8bb201c6fd55ea5e645f2d8a07248593d177910
    A
    git-svn -id:$ SVN_URL ... / trunk @ 1 ...

    正如您所见,提交D没有git-svn-id行,但是提交C有一个,那行指向trunk,所以你必须更新refs / remotes / trunk来提交C:

      $ git update-ref refs / remotes / trunk 4df9f21346526c6505a954d8310637864710308d 


  4. 如果您有很多分支和标签,请针对我们上面指定的映射对它们重复相同的步骤:


    • branches / foo => refs / remotes / foo

    • >

  5. 最后一步是恢复.git / svn目录中的映射:

      $ git svn fetch 
    从git-svn v1布局迁移...
    存在以前版本git-svn的数据,但
    .git / s vn
    (git-svn的此版本(X.Y.Z)需要)不存在。
    完成从git-svn v1布局迁移
    重建.git / svn / refs / remotes / trunk / .rev_map.694389ff-b137-4359-84f9-4d1a25628e89 ...
    r1 = d8bb201c6fd55ea5e645f2d8a07248593d177910
    R2 = 116a6760d3e278aa4d54f5bb22e531d30d731661
    R3 = 4df9f21346526c6505a954d8310637864710308d
    完成重建的.git / SVN /参/遥控器/中继/ .rev_map.694389ff-b137-4359-84f9-4d1a25628e89


最后一条命令还从SVN服务器获取新版本。命令完成后,你有一个Subversion版本库的git-svn克隆。这个版本库中的历史已经发生了变化,所以你必须像通常一样同步SVN和Git版本库之间的变化:

  $ git svn rebase 
$ git svn dcommit

希望有帮助。


I used git svn to import an existing Subversion repo into git. I then pushed this to git repo on a git server. Over the last few months changes to the software have been made in both Subversion and git repositories. Unfortunately, my local copy with the links between svn and git has been deleted.

I've tried to recreate the local copy using git svn again, but when I do a pull from the git server it complains warning: no common conflicts and I end up merging two separate branches with the same commits at the start. Like this:

F
|\
| \
E  D
|  |
C  C
|  |
B  B
|  |
A  A

How can I get it to treat the svn changes like they happened on a branch from the original repo?

F
|\
| \
E  D
| /
|/
C
|
B
|
A

解决方案

By default git-svn stores mapping between SVN revisions and Git commits in commit messages. Do you see these git-svn-id lines for older commits in your original Git repository? Here I mean that Git repository hosted on the Git server and not that one you've fetched from SVN recently.

If so, you actually didn't loose any links and git-svn should be able to restore the necessary data from the history. Though due to some compatibility issues between different versions of git-svn this may be a bit tricky:

  1. Clone your original Git repository:

    $ git clone $GIT_SERVER repo
    $ cd repo
    

  2. Update git-svn configuration in .git/config:

    $ git config svn-remote.svn.url $SVN_URL
    $ git config svn-remote.svn.fetch trunk:refs/remotes/trunk
    $ git config svn-remote.svn.branches branches/*:refs/remotes/*
    $ git config svn-remote.svn.tags tags/*:refs/remotes/tags/*
    

  3. Now you have to update refs/remotes/* refs to the latest commits with git-svn-id line:

    $ git log --first-parent refs/heads/master
    commit d566edf5f77ae0a2f7418c40949757e75ef8e83c
    D
    
    commit 4df9f21346526c6505a954d8310637864710308d
    C
    git-svn-id: $SVN_URL .../trunk@3...
    
    commit 116a6760d3e278aa4d54f5bb22e531d30d731661
    B
    git-svn-id: $SVN_URL .../trunk@2...
    
    commit d8bb201c6fd55ea5e645f2d8a07248593d177910
    A
    git-svn-id: $SVN_URL .../trunk@1...
    

    As you can see commit D does not have git-svn-id line, but commit C has one and that line refers to trunk, so you have to update refs/remotes/trunk to commit C:

    $ git update-ref refs/remotes/trunk 4df9f21346526c6505a954d8310637864710308d
    

  4. If you have many branches and tags, repeat the same steps for them with respect to the mapping we've specified above:

    • branches/foo => refs/remotes/foo

    • tags/1.0 => refs/remotes/tags/1.0

  5. The final step is to restore the mapping in .git/svn directory:

    $ git svn fetch
    Migrating from a git-svn v1 layout...
    Data from a previous version of git-svn exists, but
        .git/svn
        (required for this version (X.Y.Z) of git-svn) does not exist.
    Done migrating from a git-svn v1 layout
    Rebuilding .git/svn/refs/remotes/trunk/.rev_map.694389ff-b137-4359-84f9-4d1a25628e89...
    r1 = d8bb201c6fd55ea5e645f2d8a07248593d177910
    r2 = 116a6760d3e278aa4d54f5bb22e531d30d731661
    r3 = 4df9f21346526c6505a954d8310637864710308d
    Done rebuilding .git/svn/refs/remotes/trunk/.rev_map.694389ff-b137-4359-84f9-4d1a25628e89
    

The last command also fetches new revisions from SVN server. After the command is done you have a git-svn clone of Subversion repository. The history in this repository has diverged, so you have to synchronize changes between SVN and Git repositories as usually:

$ git svn rebase
$ git svn dcommit

Hope that helps.

这篇关于我如何重新连接一个svn仓库的git仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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