【问题标题】:Is there a way to import svn history into git after the fact?事后有没有办法将svn历史导入git?
【发布时间】:2010-10-12 08:41:14
【问题描述】:

我已经签出了一个 svn 只读 repo(svn co 而不是 git svn)。我使用 git 进行了一些更改和提交,然后将其推送到 github。

此时,git 并没有来自 svn 的所有历史记录。我想知道此时是否有办法提取和导入它。

各种 git-svn 指南展示了如何导入一个干净的 repo 并传输历史记录,但不是我能找到的已经在使用的。

【问题讨论】:

    标签: svn git github git-svn


    【解决方案1】:

    要完成Thilogood answer,一旦您将svn 存储库导入到git 中,您可以使用merging in unrelated git branches 中详述的脚本将该git 存储库添加到您的存储库中

    #!/bin/bash
    
    set -e
    
    if test -z "$2" -o -n "$3"; then
        echo "usage: $0 REPO BRANCHNAME" >&2
        exit 1
    fi
    
    repo=$1
    branch=$2
    
    git fetch "$repo" "$branch"
    
    head=$(git rev-parse HEAD)
    fetched=$(git rev-parse FETCH_HEAD)
    headref=$(git rev-parse --symbolic-full-name HEAD)
    
    git checkout $fetched .
    
    tree=$(git write-tree)
    
    newhead=$(echo "merged in branch '$branch' from $repo" | git commit-tree $tree -p $head -p $fetched)
    git-update-ref $headref $newhead $head
    git reset --hard $headref
    

    其他方法包括:

    • 尝试“简单”git pull REPO BRANCH
    • using git grafts to restore svn merge history 通过在 .git/info/grafts 创建一个文本文件,其中每一行包含一个提交 id,后跟其父项。此后,您的本地存储库将就好像该提交实际上是父母双方的后代一样。

    【讨论】:

      【解决方案2】:

      您可能需要将 svn 导入到一个新的 git 存储库中,合并两个存储库(只需将它们添加在一起,它可能会抱怨它们不相关)然后 rebase 您对导入的历史所做的更改.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-30
        • 2010-09-10
        • 1970-01-01
        • 1970-01-01
        • 2010-09-11
        • 1970-01-01
        相关资源
        最近更新 更多