当前位置:   article > 正文

SVN工程转Git工程&Github托管_as项目原来用的是svn,现在用github如何操作

as项目原来用的是svn,现在用github如何操作

1. 介绍

鉴于很多项目以前是使用SVN进行管理的,最近打算逐步将一些代码开源出来,以便需要的朋友使用。这就不可避免的出现了SVN代码如何转到Github上的问题。

主要的问题是希望之前的上传记录不要丢失,这里结合一个例子正好整理和测试下命令是否可以正常的将SVN代码转到Github进行托管。

2. autoAudioTest之SVN转Github步骤

Step 1 工作环境(ubuntu)

$ uname -a
Linux daniel-ThinkPad-SL410 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Step 2 安装升级必要软件

这里可能涉及一些工作环境之前已经预装的软件,比如:java等

注:下面这些软件是必须的,就特地强调一下。

$ mkdir GitMigration
$ cd GitMigration
$ sudo apt-get install subversion git git-svn
  • 1
  • 2
  • 3

Step 3 转换脚本

Download svn-migration-scripts.jar

$ wget https://bitbucket.org/atlassian/svn-migration-scripts/downloads/svn-migration-scripts.jar
  • 1

注:感觉这个并不重要,因为实际对工程项目了解的话,看下日志记录,可以自己写那个author.txt文档。

Step 4 检查软件运行环境

$ java -jar svn-migration-scripts.jar verify
svn-migration-scripts: using version 0.1.56bbc7f
Git: using version 2.25.1
Subversion: using version 1.13.0
git-svn: using version 2.25.1
  • 1
  • 2
  • 3
  • 4
  • 5

Step 5 生成authors.txt

主要目的是为了导出并修改后续github中每个commit的作者名字及联系方式

$ java -jar svn-migration-scripts.jar authors svn://192.168.68.200/BloodDiamond-Echo > authors.txt
$ cat authors.txt
lida = lida <lida@mycompany.com>
root = root <root@mycompany.com>
  • 1
  • 2
  • 3
  • 4

修改为如下格式:

$ vi authors.txt
$ cat authors.txt
lida = lida <lida-mail@163.com>
root = root <lida_mail@163.com>
  • 1
  • 2
  • 3
  • 4

Step 6 SVN转换Git格式

$ git svn clone --stdlayout --authors-file=./authors.txt svn://192.168.68.200/BloodDiamond-Echo autoAudioTest
Initialized empty Git repository in /home/daniel/GitMigration/autoAudioTest/.git/
        A       readme.txt
r1 = b230af6744d36fc61b00327a344aad7c8a31dc12 (refs/remotes/origin/trunk)
        A       autoAudioTest.py
        M       readme.txt
        A       tests/desktop.ini
        A       tests/sample_tmjl/steps.ini
        A       tests/sample_tmjl/tmjl-turnoff-light.mp3
        A       tests/sample_tmjl/tmjl-turnon-light.mp3
        A       utility/ping.py
        A       utility/setup/hello.py
        A       utility/setup/setup.py
        A       utility/setup/setup_hello.py
W: +empty_dir: trunk/modules
r2 = 3cc5696845e2a0a334d4c56d6d5d30c9616955db (refs/remotes/origin/trunk)
W: +empty_dir: trunk/release
W: +empty_dir: trunk/thirdparty
r3 = c6e7bce2f8e672aa1656ffa76b2fe60ac814358c (refs/remotes/origin/trunk)
        A       utility/ask_y_n.py
        A       utility/playmp3.py
r4 = b9d8c0484a0bbe17f5256535057e3b747b95091f (refs/remotes/origin/trunk)
        M       autoAudioTest.py
r5 = da0a3331de626868d22d642daf6516d16ab1ee56 (refs/remotes/origin/trunk)
        A       setup.py
        D       utility/setup/setup.py
W: -empty_dir: trunk/utility/setup/setup.py
r6 = 6f365ae5c8e9ad7b9e3a65673387f34230213cab (refs/remotes/origin/trunk)
        M       autoAudioTest.py
r7 = 3fdcd4d1a92d2f64cba7411203c54c3ccf7dface (refs/remotes/origin/trunk)
        M       readme.txt
r8 = a7fa94984f98bfb28b7691161151df853d0e5433 (refs/remotes/origin/trunk)
        A       release/autoAudioTest_v1.1.8.exe
        A       releaseNotes.txt
r9 = 827031b61bfd07e465667410d1c4ca3dc9dc4243 (refs/remotes/origin/trunk)
        M       autoAudioTest.py
        A       modules/__init__.py
        A       modules/comfunc.py
r10 = 2f5e0fd8b45813393b3d3350cee9e40ba98b6ae4 (refs/remotes/origin/trunk)
        A       logs/v010108/t1500_steps.ini
        A       logs/v010108/t1500_tmjl_result.log
        A       logs/v010108/t3000_steps.ini
        A       logs/v010108/t3000_tmjl_result.log
        A       logs/v010108/t8000_steps.ini
        A       logs/v010108/t8000_tmjl_result.log
        A       logs/v010108/t800_steps.ini
        A       logs/v010108/t800_tmjl_result.log
r11 = e213651fe01a56ad4f6d19c86cb173c01abe2065 (refs/remotes/origin/trunk)
        A       releaseSteps.txt
r12 = 6a2fba962d8961ae69fad62774578c95627b95e7 (refs/remotes/origin/trunk)
        M       releaseSteps.txt
r13 = ccac0a0e8e4e9f0b0bd3c00e74443f5d139b7c11 (refs/remotes/origin/trunk)
Checked out HEAD:
  svn://192.168.68.200/BloodDiamond-Echo/trunk r13
creating empty directory: thirdparty


$ cd autoAudioTest/
$ git branch -a
* master
  remotes/origin/trunk
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

注:鉴于我们通常是标准的SVN目录管理格式,所以用常规方法即可。

Step 7 Github新建空工程

这一步是Github的操作,这里就忽略了。

注:如果有不太清楚的同学,点击Github上自己【个人头像】–>【Your repositoris】–>【New】新建。

在这里插入图片描述在这里插入图片描述

Step 8 Git提交已有工程

进入新建空白工程【code】页面,提示几种新建工程的方法:
在这里插入图片描述

Step 9 Git提交经转换的SVN工程

$ git remote add origin git@github.com:lida2003/autoAudioTest.git
$ git remote -v
origin  git@github.com:lida2003/autoAudioTest.git (fetch)
origin  git@github.com:lida2003/autoAudioTest.git (push)
$ git branch -m master main
$ git push --set-upstream origin main
Enumerating objects: 67, done.
Counting objects: 100% (67/67), done.
Delta compression using up to 2 threads
Compressing objects: 100% (62/62), done.
Writing objects: 100% (67/67), 146.91 MiB | 1.77 MiB/s, done.
Total 67 (delta 28), reused 0 (delta 0)
remote: Resolving deltas: 100% (28/28), done.
remote: error: Trace: eff12eb073130c07d552e733901a707ae6aabee5593ff671aee8df6c4d6b7323
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File release/autoAudioTest_v1.1.8.exe is 145.55 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To github.com:lida2003/autoAudioTest.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:lida2003/autoAudioTest.git'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

Step 10 解决GH001: Large files detected

看下日志说的“release/autoAudioTest_v1.1.8.exe”是那次提交引入的。

$ git log -n 6
commit ccac0a0e8e4e9f0b0bd3c00e74443f5d139b7c11 (HEAD -> main, origin/trunk)
Author: lida <lida-mail@163.com>
Date:   Tue Jul 19 13:00:14 2022 +0000

    国内本地镜像源更新

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@13 694d3844-2e77-45a3-bfb9-1339a5765990

commit 6a2fba962d8961ae69fad62774578c95627b95e7
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:33:57 2019 +0000

    releaseSteps.txt from previous knowledge to compile and pack to exe command line tools

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@12 694d3844-2e77-45a3-bfb9-1339a5765990

commit e213651fe01a56ad4f6d19c86cb173c01abe2065
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:31:38 2019 +0000

    v1.1.8 test data from field

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@11 694d3844-2e77-45a3-bfb9-1339a5765990

commit 2f5e0fd8b45813393b3d3350cee9e40ba98b6ae4
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:27:10 2019 +0000

    move some function from autoAudioTest.py to modules/comfunc.py and make it work.

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@10 694d3844-2e77-45a3-bfb9-1339a5765990

commit 827031b61bfd07e465667410d1c4ca3dc9dc4243
Author: lida <lida-mail@163.com>
Date:   Wed Jan 30 07:35:53 2019 +0000

    autoAudioTest_v1.1.8 Release upload

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@9 694d3844-2e77-45a3-bfb9-1339a5765990

commit a7fa94984f98bfb28b7691161151df853d0e5433
Author: lida <lida-mail@163.com>
Date:   Wed Jan 30 07:19:14 2019 +0000

    add readme for software "BREACH OF CONTRACT AND RESPONSIBILITY OF EXEMPTION"

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@8 694d3844-2e77-45a3-bfb9-1339a5765990

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

我们进一步具体可以看到 Commit-ID为827031b61bfd07e465667410d1c4ca3dc9dc4243提交了两个文件:

  1. release/autoAudioTest_v1.1.8.exe
  2. releaseNotes.txt
$ git show 827031b61bfd07e465667410d1c4ca3dc9dc4243
commit 827031b61bfd07e465667410d1c4ca3dc9dc4243
Author: lida <lida-mail@163.com>
Date:   Wed Jan 30 07:35:53 2019 +0000

    autoAudioTest_v1.1.8 Release upload

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@9 694d3844-2e77-45a3-bfb9-1339a5765990

diff --git a/release/autoAudioTest_v1.1.8.exe b/release/autoAudioTest_v1.1.8.exe
new file mode 100644
index 0000000..5d4a7e8
Binary files /dev/null and b/release/autoAudioTest_v1.1.8.exe differ
diff --git a/releaseNotes.txt b/releaseNotes.txt
new file mode 100644
index 0000000..3ed0720
--- /dev/null
+++ b/releaseNotes.txt
@@ -0,0 +1,15 @@
+^M
+^M
+###########################################################^M
+### autoAudioTest_v1.0.6^M
+###########################################################^M
+^M
+# First Releasse^M
+^M
+# MD5SUM^M
+【1】autoAudioTest.exe^M
+==》c683c23f723f9527ef1495c40c5f4197^M
+【2】autoAudioTest_v1.1.8.exe^M
+==》dbac807ea546e50e5cc0a6575c511ad4^M
+^M
+# Know Bugs^M

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

保存上述两个文件,并进行rebase,丢弃上述Commit-ID为827031b61bfd07e465667410d1c4ca3dc9dc4243的提交

$ git rebase -i a7fa94984f98bfb28b7691161151df853d0e5433
Successfully rebased and updated refs/heads/main.
  • 1
  • 2

在这里插入图片描述最新rebase的git 日志显示如下:

$ git log -n 6
commit db6879ce6303db395b36fc7bfc514876700a536b (HEAD -> main)
Author: lida <lida-mail@163.com>
Date:   Tue Jul 19 13:00:14 2022 +0000

    国内本地镜像源更新

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@13 694d3844-2e77-45a3-bfb9-1339a5765990

commit 9fb35d98a4ac2134141f2969f27897e0cc55363c
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:33:57 2019 +0000

    releaseSteps.txt from previous knowledge to compile and pack to exe command line tools

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@12 694d3844-2e77-45a3-bfb9-1339a5765990

commit 05a04613572cee06a862c1cb1a56278e0882d8ba
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:31:38 2019 +0000

    v1.1.8 test data from field

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@11 694d3844-2e77-45a3-bfb9-1339a5765990

commit 576f8436f69bdf2c6b449d97dadb269b74e59ea8
Author: lida <lida-mail@163.com>
Date:   Sun Mar 3 03:27:10 2019 +0000

    move some function from autoAudioTest.py to modules/comfunc.py and make it work.

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@10 694d3844-2e77-45a3-bfb9-1339a5765990

commit a7fa94984f98bfb28b7691161151df853d0e5433
Author: lida <lida-mail@163.com>
Date:   Wed Jan 30 07:19:14 2019 +0000

    add readme for software "BREACH OF CONTRACT AND RESPONSIBILITY OF EXEMPTION"

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@8 694d3844-2e77-45a3-bfb9-1339a5765990

commit 3fdcd4d1a92d2f64cba7411203c54c3ccf7dface
Author: lida <lida-mail@163.com>
Date:   Wed Jan 30 06:40:44 2019 +0000

    Fix internal player use configuration read issue.

    git-svn-id: svn://192.168.68.200/BloodDiamond-Echo/trunk@7 694d3844-2e77-45a3-bfb9-1339a5765990

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

Step 11 Git再次提交经转换的SVN工程

$ git push --set-upstream origin main
Enumerating objects: 62, done.
Counting objects: 100% (62/62), done.
Delta compression using up to 2 threads
Compressing objects: 100% (57/57), done.
Writing objects: 100% (62/62), 1.60 MiB | 756.00 KiB/s, done.
Total 62 (delta 27), reused 0 (delta 0)
remote: Resolving deltas: 100% (27/27), done.
To github.com:lida2003/autoAudioTest.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

Step 12 Github刷新工程

在这里插入图片描述
Rebase后面的git记录在web页面上显示是rebase的时间,不过git log下还是以前的时间。
在这里插入图片描述

3. autoAudioTest之单循环测试视频

天猫精灵+YeeLight 智能灯泡+电压电流计+2019自动测试

4. autoAudioTest手册&版本

5. 参考资料

【1】Migrate from SVN to Git

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/670288
推荐阅读
相关标签
  

闽ICP备14008679号