SVN迁移至GitLab,并附带历史提交记录(二)

《SVN迁移至GitLab,并附带历史提交记录》用的 git svn clone不同,本文使用svn2git来迁移项目代码。

一、准备工作

  1. 安装Git环境,配置本地git账户信息:
bash 复制代码
git config --global user.name "XXX"
git config --global user.email "XXX@mail.com"

可通过命令git config -l 查看结果

  1. 安装git-svn,运行git svn -h,若正常输出帮助信息,说明安装没问题。
  2. 安装ruby,运行ruby -h,若正常输出帮助信息,说明安装没问题。
  3. 执行下面命令安装svn2git,注意下面命令依赖ruby。
bash 复制代码
gem install svn2git

再运行svn2git -h,若正常输出帮助信息,说明安装没问题。

  1. svn账号与git账号映射,新建文件 userinfo.txt,左侧是SVN的账号,右侧是git账号信息,用=号连接:

    svn1=git1git1@mail.com
    svn2=git2git2@mail.com
    svn3=gitxgitx@mail.com

注意:

  • 需要将涉及到的同步记录中的用户都做映射,否则在同步时可能会报错
  • 对于无法对应的人员,如离职人员,有SVN账号,但是没有现在的GIT账号,保险起见,可以采用无关紧要的账号进行对应,或者单独建一个账号也可以,例如使用的test账号进行标识的

二、导出SVN项目至本地

  1. 创建空文件夹用于存放SVN的代码,并将userinfo.txt文件放置在同一层级

    │ userinfo.txt
    └─ MyProject

  2. 鼠标右键 选中Git Bash Here 进入git命令行,执行:

bash 复制代码
svn2git svnUrl --authors userinfo.txt -v

这里的-v会输出执行过程的信息,方便debug。此处的 -r 12345:HEAD 表示从svn的12345版本到最新版本的提交记录,避免拉取所有数据量过大,操作耗时高。svnurl是svn项目地址。如果需要拉取所有记录,可去除 -r 12345:HEAD

如果在windows有下面错误:

复制代码
D:\MyProject>svn2git https:/xxx.com:8443/svn/SVN2GIT/ --authors authors.txt -v
Running command: git svn init --prefix=svn/ --no-metadata --trunk='trunk' --tags='tags' --branches='branches'  https:/xxx.com:8443/svn/SVN2GIT/
Initialized empty Git repository in D:/MyProject/.git/
Running command: git config --local --get user.name
Running command: git config --local svn.authorsfile authors.txt
Running command: git svn fetch
Running command: git branch -l --no-color
Running command: git branch -r --no-color
Running command: git config --local --get user.name
Running command: git config --local --get user.email
Running command: git checkout -f master
error: pathspec 'master' did not match any file(s) known to git
command failed:
git checkout -f master

去安装目录C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\svn2git-2.4.0\lib\svn2git,找到migration.rb文件,把#{trunk}#{tag}#{branch}两边的单引号删除,再重新执行上面命令。

参考自:svn2git - command failed

三、与远程git仓库关联起来

  1. 进入项目文件夹,
bash 复制代码
cd MyProject
  1. 关联远程事先创建好的git项目
bash 复制代码
git remote add origin gitURL

如:git remote add origin http://192.168.1.xx:5678/MyProject.git

  • 查看关联情况:
bash 复制代码
git remote -v
  • 如果关联有误,可以删除关联
bash 复制代码
git remote rm origin
  1. 推送本地项目到git仓库
  • 提交记录之前,先拉取远程git项目文件(如:README.md),否则直接提交会报错
bash 复制代码
git pull --rebase origin master
  • 拉取成功后,执行push命令
bash 复制代码
git push -u origin master

执行命令后,可能会弹窗要求输入Git的账号和密码

相关推荐
牛奶咖啡133 小时前
Git实践——GitLab服务器的部署与使用
gitlab·gitlab是什么·gitlab有啥用·gitlab适用场景·gitlab的版本如何选·安装部署gitlab·gitlab的使用
lisanmengmeng1 天前
Gitlab搭建
gitlab
dapeng-大鹏3 天前
记一次 GitLab Let‘s Encrypt 证书申请失败的排查与修复
gitlab
JAVA面经实录9173 天前
Java开发工程基础完整手册(企业实战完整版)
java·开发语言·git·ci/cd·svn·github·intellij idea
身如柳絮随风扬3 天前
使用 Docker 部署 GitLab 并分配用户账号 —— 保姆级教程
docker·容器·gitlab
鼎道开发者联盟4 天前
鼎享会 | 从手工到自动化:OpenClaw改造GitLab内部协作流程的全过程
自动化·gitlab·openclaw
ℳ₯㎕ddzོꦿ࿐5 天前
告别手工发版:用 GitLab CI/CD 打通前后端自动化部署的“任督二脉”
ci/cd·自动化·gitlab
ℳ₯㎕ddzོꦿ࿐5 天前
实战:在 Linux 系统用 Docker-Compose 优雅部署 GitLab 及防坑指南
linux·docker·gitlab
源图客5 天前
Linux(CentOS9)服务器部署gitlab-ce-18.11.1-ce.0.el9.x86_64.rpm
linux·服务器·gitlab
ℳ₯㎕ddzོꦿ࿐5 天前
实战篇:结合 GitLab CI/CD 实现 Spring Cloud 微服务自动化部署与防坑指南
spring cloud·ci/cd·gitlab