从 SVN 迁移到 Git
大约 2 分钟
这里主要说一下 SVN 迁移到 Git 。
我们以前迁移的时候太过粗暴,直接新建个 Git 仓库,把 SVN 的代码 copy 进来,直接提交就完了。这给我们以后的工作甩锅都造成了不小的影响。
如果项目体量不大,开发人员不多,简单粗暴点也还好。但是因为当时的那个项目很大,迭代了有几年了,后面有些遗留的生产问题报出来,这时候想找当事人就很难了,因为没有迁移前的代码更新记录了,只有一个提交记录。所以迁移的时候还是要注意方法。
如果要做这样的大项目迁移工作,而且要带上提交记录,那最好还是要用 git svn
命令。
# clone 项目
git svn clone https://f69j2gkvb3upvz7/svn/mypro4_git_svn
这样拉下来的项目是带有提交日志等信息的。
$ git log
commit a66548dab43982fbcf05b43cf24abdec46ff930e (HEAD -> master, git-svn)
Author: will <will@7adf1bb6-8b8d-ba41-906b-aa243fc2b489>
Date: Sun Sep 20 17:44:41 2020 +0000
merge
git-svn-id: https://f69j2gkvb3upvz7/svn/mypro4_git_svn@5 7adf1bb6-8b8d-ba41- 906b-aa243fc2b489
commit 805ae86b6428fc039ec58b500a74406312b7f2fd
Author: will <will@7adf1bb6-8b8d-ba41-906b-aa243fc2b489>
Date: Sun Sep 20 17:40:52 2020 +0000
update version2
git-svn-id: https://f69j2gkvb3upvz7/svn/mypro4_git_svn@4 7adf1bb6-8b8d-ba41- 906b-aa243fc2b489
# 添加远程仓库
git remote add origin https://gitee.com/willcoder/my_svn_git.git
当然这个仓库地址是真实存在的,我是直接在 Gitee 上建的一个测试。
如果这一步的时候提示:
fatal: remote origin already exists.
那就先删除远程仓库再添加。
$ git remote rm origin
# 推送到远程仓库
$ git push https://gitee.com/willcoder/my_svn_git.git
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (15/15), 1.37 KiB | 233.00 KiB/s, done.
Total 15 (delta 3), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-5.0]
To https://gitee.com/willcoder/my_svn_git.git
* [new branch] master -> master
# 验证是否成功
新建一个文件夹,然后再将远程仓库 clone 下来:
$ git clone https://gitee.com/willcoder/my_svn_git.git
Cloning into 'my_svn_git'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 15 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (15/15), done.
通过 git log
查看记录:
$ git log
commit 55bbeea2d8b31d0bc27e4950ef6eab550e3ef21a (HEAD -> master, origin/master, origin/HEAD)
Author: will <willcoder@qq.com>
Date: Mon Sep 21 01:41:45 2020 +0800
test commit 2
commit a208b7c1c2adc4132e1b88b4cbf09ba98100746f
Author: will <will@7adf1bb6-8b8d-ba41-906b-aa243fc2b489>
Date: Sun Sep 20 17:37:41 2020 +0000
test commit
git-svn-id: https://f69j2gkvb3upvz7/svn/mypro4_git_svn@3 7adf1bb6-8b8d-ba41-906b-aa243fc2b489
commit a5f6fc84e95098a1c1cfb9b9c07d20aa9d8b9056
Author: will <will@7adf1bb6-8b8d-ba41-906b-aa243fc2b489>
Date: Sun Sep 20 17:28:54 2020 +0000
version2
git-svn-id: https://f69j2gkvb3upvz7/svn/mypro4_git_svn@2 7adf1bb6-8b8d-ba41-