svn迁移至git 保留提交记录

  1. 生成一个authors.txt文件。这将包含您的SVN用户和Gitlab用户之间的映射: 可以跳过

    • 从现有的svn存储库中: svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
    • 否则,请按照以下格式手动创建它:

      oldSVNusername = newGitlabUsername <gitlabRegisteredEmailAddress@example.com>

  2. 创建一个临时目录初始化SVN存储库

    • mkdir temp
    • cd temp
    • git svn init --no-metadata http://username:password@example.com:81/svn/myrepository
  3. 配置git

    • git config svn.authorsfile ~/authors.txt 可以跳过
    • git config --global user.name myusername
    • git config --global user.email myusername@example.com
  4. 抓取文件并将其克隆到新的git repo中

    • git svn fetch
    • git clone . ../myrepository
    • cd ../myrepository
  5. 在gitlab中设置新的存储库,确保您的用户可以访问它。

  6. 添加一个远程gitlab存储库

    • git remote add gitlab gitlab.example.com:gitlab-group/myrepository.git
    • 也可以使用gitlib提示信息操作
    • Git 全局设置
      git config --global user.name "bo wang"
      git config --global user.email "wb2110@qq.com"
      
      创建一个新仓库
      git clone http://gitlab.xxx.com/web-ui.git
      cd web-ui
      touch README.md
      git add README.md
      git commit -m "add README"
      git push -u origin master
      推送现有文件夹
      cd existing_folder
      git init
      git remote add origin http://gitlab.xxx.com/web-ui.git
      git add .
      git commit -m "Initial commit"
      git push -u origin master
      推送现有的 Git 仓库
      cd existing_repo
      git remote rename origin old-origin
      git remote add origin http://gitlab.xxx.com/web-ui.git
      git push -u origin --all
      git push -u origin --tags
  7. 仔细检查您的配置myrepository/.git/config(尤其是URL行)

    [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = /root/temp/. fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = gitlab merge = refs/heads/master [remote "gitlab"] url = http://gitlab.example.com/gitlab-group/myrepository.git fetch = +refs/heads/*:refs/remotes/gitlab/* [user] name = myusername

  8. 将其全部推向上游

    • git push --set-upstream gitlab master

搬运from:https://stackoverflow.com/questions/35900710/svn-to-git-conversion-correct-remote-ref-must-start-with-refs-error

posted @ 2021-05-25 19:54  wolbo  阅读(195)  评论(1编辑  收藏  举报