8

(我发布这个问题的目的是自己回答,因为我在其他地方找不到答案。希望它会帮助遇到同样问题的其他人,并且下次我尝试这样做时会帮助我。)

挑战

我想将 SVN 存储库转换为本地托管的 gitlab GIT 存储库并维护历史记录。

设置

Gitlab 8.5,Ubuntu 14.04 LTS,颠覆 1.8.8

问题

最初尝试使用 git-svn 或 svn2git 从 svn 转换为 git 导致以下错误。

错误

svn-remote.svn: remote ref '//example.com:81/svn/myrepository/trunk:refs/remotes/trunk' must start with 'refs/'

我试过的

我在下面的外部参考资料中遵循了这两个指南。

使用的外部参考

4

3 回答 3

13
  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. 创建一个临时目录 init SVN repo

    • 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
  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

现在您应该将所有文件和历史记录转换为 git 并在 gitlab 中显示。

于 2016-03-09T19:20:16.200 回答
6

删除前导 / 斜线对我有用:

这将不起作用:

git svn clone "http://..." --prefix=svn/ --trunk=/trunk --branches=/branches --tags=/tags  --authors-file "authors-transform.txt" "C:\Temp\GitRepos"

这有效:

git svn clone "http://..." --prefix=svn/ --trunk=trunk --branches=branches --tags=tags  --authors-file "authors-transform.txt" "C:\Temp\GitRepos"
于 2019-10-21T16:21:15.090 回答
1

它唤醒我的是删除 .git 目录并运行下一个命令:

git svn clone --authors-file=authors.txt --no-metadata http://svn.companie.com/REP/mock/ -s mock
于 2019-10-17T13:18:02.093 回答