代码之家  ›  专栏  ›  技术社区  ›  Jauder Ho

有没有办法在事后将svn历史导入git?

  •  7
  • Jauder Ho  · 技术社区  · 17 年前

    在这一点上,git并没有来自svn的所有历史记录。我想知道在这一点上是否有一种方法可以提取和导入这个。

    2 回复  |  直到 17 年前
        1
  •  8
  •   Community Mohan Dere    9 年前

    完成 Thilo 的 good answer ,将svn repo导入git repo后,可以使用脚本将该git存储库添加到您的存储库中,如中所述 merging in unrelated git branches

    #!/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处创建一个文本文件,其中每行包含一个commit id,后跟其父行。此后,您的本地存储库的行为就好像该提交实际上是从双亲继承的一样。
        2
  •  6
  •   Thilo    17 年前

    rebase 您对导入的历史记录所做的更改。