svn迁移到git
I have worked with SVN for a long time and recently I have started working on Git. After getting familiar with Git, I can clearly say that it’s far better than SVN. If you work with multiple branches and take a merge between branches or reintegrate (svn terminology) then you will know the benefit of Git over SVN.
我已经在SVN上工作了很长时间,最近我开始研究Git。 熟悉Git之后,我可以清楚地说它比SVN好得多。 如果您使用多个分支机构,并在分支机构之间进行合并或重新集成(SVN术语),那么您将了解Git优于SVN的优势。
I have recently moved my Google Code project to Github since google code is closed, so I thought to write a tutorial on SVN to Git Migration.
自从Google代码关闭以来,我最近将我的Google Code项目移到了Github,所以我想写一篇关于SVN到Git Migration的教程。
First we will look into using Git native commands to migrate the SVN repository to Git repository and then see what are the drawbacks and then we will do the same thing with SVN2Git tool.
首先,我们将研究使用Git本机命令将SVN存储库迁移到Git存储库,然后看看有哪些缺点,然后我们将使用SVN2Git工具执行相同的操作 。
SVN and Git Repositories Details:
SVN和Git存储库详细信息:
https://pl6.projectlocker.com/JournalDev/JDProject/svn
. Below image shows the directory structure.Notice that I have a standard directory structure with trunk, branches and tags. I have also created an extra file (README.txt) that is outside this directory hierarchy.
SVN存储库 :我已经在线创建了一个公共存储库,其URL是https://pl6.projectlocker.com/JournalDev/JDProject/svn
。 下图显示了目录结构。 注意,我有一个带有主干 , 分支和标签的标准目录结构。 我还创建了一个额外的文件(README.txt),该文件不在此目录层次结构中。
https://github.com/pankaj0323/JDProjects.git
GIT存储库 :我正在使用Github作为我的存储库。 它是免费使用的,我的项目git URL是https://github.com/pankaj0323/JDProjects.git
$ svn log -q https://pl6.projectlocker.com/JournalDev/JDProject/svn | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors.txt
After this, you will have authors.txt file that will have all the authors details who have committed code into this SVN project.
之后,您将拥有authors.txt文件,其中将包含已向该SVN项目提交代码的所有作者详细信息。
$ svn log --stop-on-copy https://pl6.projectlocker.com/JournalDev/JDProject/svn
You will get the first revision number, if you have a bigger project with release cycles and you are importing from specific release, then this number could be something different. For me it’s 1 because I just created this sample SVN project for this tutorial.
您将获得第一个修订版本号,如果您有一个较大的项目并具有发行周期,并且要从特定发行版中导入,则此版本号可能有所不同。 对我来说是1,因为我刚刚为本教程创建了这个示例SVN项目。
git svn clone
to convert your SVN project into Git. Use revision number when your project repository was created.Passing –no-minimize-url will allow git svn to accept URLs as-is without attempting to connect to a higher level directory.
For other options, read git-svn documentation.
$ git svn clone -r1:HEAD --no-minimize-url --stdlayout --no-metadata --authors-file authors.txt https://pl6.projectlocker.com/JournalDev/JDProject/svn
Initialized empty Git repository in /Users/pankaj/temp/SVN_TO_GIT/svn/.git/
r2 = 06ca74b0800199e459628cec09a559491da39999 (refs/remotes/origin/trunk)
A abc.html
r3 = ba90b46b60785a7fbd583e4ac197e4e8052e61b5 (refs/remotes/origin/trunk)
A ClassM2.java
r4 = 3667ce254366e8e020b6e9516979695d9f00f1b9 (refs/remotes/origin/trunk)
Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk => https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch, 4
Found branch parent: (refs/remotes/origin/MyDevBranch) 3667ce254366e8e020b6e9516979695d9f00f1b9
Following parent with do_switch
Successfully followed parent
r5 = 6b78ccabce56601ef6de255eab6d7fcd8980f99b (refs/remotes/origin/MyDevBranch)
A branch_file.txt
r6 = c940c6a4cc2b357985867ca239fba7b91e7038e5 (refs/remotes/origin/MyDevBranch)
Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch => https://pl6.projectlocker.com/JournalDev/JDProject/svn/tags/MyDevBranch-1.0, 6
Found branch parent: (refs/remotes/origin/tags/MyDevBranch-1.0) c940c6a4cc2b357985867ca239fba7b91e7038e5
Following parent with do_switch
Successfully followed parent
r7 = 3041d81b3a4fec5f4ca1b2e04ad5730f67e677b9 (refs/remotes/origin/tags/MyDevBranch-1.0)
Checked out HEAD:
https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk r4
$
运行以下命令以使用git svn clone
将SVN项目转换为Git。 创建项目存储库时,请使用修订号。 传递–no-minimize-url将允许git svn照原样接受URL,而无需尝试连接到更高级别的目录。
有关其他选项,请阅读git-svn文档 。
$ cd svn
$ git remote add origin https://github.com/pankaj0323/JDProjects.git
您将创建项目目录,进入该目录并添加远程git url作为源。 $ git branch -a
* master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$
Git svn clone command makes master from trunk that is ready to be pushed to remote git repository. But we want to push branches too. Use below commands for that:
将SVN分支转换为Git分支 :如果此时将列出分支,则会得到类似以下的内容。$ git branch -a
* master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$
Git svn clone命令从准备好被推入远程git仓库的主干中创建master。 但是我们也想推动分支机构。 为此,请使用以下命令:
$git tag
$git checkout origin/tags/MyDevBranch-1.0
Note: checking out 'origin/tags/MyDevBranch-1.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 3041d81... Creating a tag
$ git branch -a
* (detached from origin/tags/MyDevBranch-1.0)
MyDevBranch
master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$ git tag -a MyDevBranch-1.0 -m "creating tag"
$git tag
MyDevBranch-1.0
$
迁移标签 :Git svn clone命令不会创建标签,请遵循以下命令来创建标签,并使它们准备好推送到远程。 git push
command to publish them to remote repository.$ git push origin master MyDevBranch MyDevBranch-1.0
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (14/14), 2.28 KiB | 0 bytes/s, done.
Total 14 (delta 3), reused 0 (delta 0)
To https://github.com/pankaj0323/JDProjects.git
* [new branch] master -> master
* [new branch] MyDevBranch -> MyDevBranch
* [new tag] MyDevBranch-1.0 -> MyDevBranch-1.0
$
将Git分支和标签推送到远程 :我的master,分支和标签已准备好推送,请使用下面的git push
命令将它们发布到远程存储库。 That’s it. We have moved our SVN project to Git. While this process seems easy, there are two drawbacks with git svn clone
.
而已。 我们已将SVN项目移至Git。 虽然这个过程看起来很简单,但是git svn clone
有两个缺点。
svn2git tool solves above two problems with native commands. Before we use this tool, we need to install it. It requires git, git-svn, and ruby installed. svn2git is a ruby wrapper around git’s native SVN support through git-svn. You can install the pre-requisites using below command.
svn2git工具使用本机命令解决了以上两个问题。 在使用此工具之前,我们需要先安装它。 它需要安装git,git-svn和ruby。 svn2git是通过git-svn围绕git的本机SVN支持的Ruby包装。 您可以使用以下命令安装必备组件。
$ sudo apt-get install git-core git-svn ruby
Once you have the necessary software on your system, you can install svn2git through rubygems, which will add the svn2git command to your PATH.
$ sudo gem install svn2git
Once svn2git is installed, use below commands to migrate SVN repository to Git.
$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
MyDevBranch
* master
remotes/svn/MyDevBranch
remotes/svn/trunk
$ git tag
MyDevBranch-1.0
$ git push origin master MyDevBranch MyDevBranch-1.0
Counting objects: 14, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (14/14), 2.32 KiB | 0 bytes/s, done.
Total 14 (delta 3), reused 14 (delta 3)
To https://github.com/pankaj0323/JDProjects.git
* [new branch] master -> master
* [new branch] MyDevBranch -> MyDevBranch
* [new tag] MyDevBranch-1.0 -> MyDevBranch-1.0
$
That’s it. We have migrated SVN repository to Git using svn2git tool. There are various options that we can use with svn2git, for example –notags if you don’t want to migrate tags. Please go through svn2git Usage section for various options. Also note that README.txt file that was not part of standard svn structure is not migrated.
That’s all for svn to git migration. Based on above analysis, svn2git tool seems a better choice to me than git svn clone
native command.
一旦在系统上安装了必要的软件,就可以通过rubygems安装svn2git,这会将svn2git命令添加到PATH中。
安装svn2git后,请使用以下命令将SVN信息库迁移到Git。
$ svn2git https://pl6.projectlocker.com/JournalDev/JDProject/svn --authors authors.txt --revision 1
Initialized empty Git repository in /Users/pankaj/temp/SVN_TO_GIT/.git/
r2 = 8beacf45e1b82b27bd27891040ea9c77b88d6c37 (refs/remotes/svn/trunk)
A abc.html
r3 = 52c125d5c68edf2ddd00143d308ba56ea0024f90 (refs/remotes/svn/trunk)
A ClassM2.java
r4 = f9863ff1c1e1ff323a2f96141c05f69278f830c5 (refs/remotes/svn/trunk)
Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk => https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch, 4
Found branch parent: (refs/remotes/svn/MyDevBranch) f9863ff1c1e1ff323a2f96141c05f69278f830c5
Following parent with do_switch
Successfully followed parent
r5 = fd5f535cf5d467df014e621ae48c22a1b7c568fa (refs/remotes/svn/MyDevBranch)
A branch_file.txt
r6 = a04dc2dfe83419ece649d9d192406f01214bd5ab (refs/remotes/svn/MyDevBranch)
Found possible branch point: https://pl6.projectlocker.com/JournalDev/JDProject/svn/branches/MyDevBranch => https://pl6.projectlocker.com/JournalDev/JDProject/svn/tags/MyDevBranch-1.0, 6
Found branch parent: (refs/remotes/svn/tags/MyDevBranch-1.0) a04dc2dfe83419ece649d9d192406f01214bd5ab
Following parent with do_switch
Successfully followed parent
r7 = f84c0a289589976fe8c879868626a096e36c98ef (refs/remotes/svn/tags/MyDevBranch-1.0)
Checked out HEAD:
https://pl6.projectlocker.com/JournalDev/JDProject/svn/trunk r4
$
而已。 我们已经使用svn2git工具将SVN信息库迁移到Git。 svn2git可以使用多种选项,例如–notags(如果您不想迁移标签)。 请浏览svn2git用法部分以了解各种选项。 还要注意,不是标准svn结构一部分的README.txt文件不会被迁移。
这就是svn到git迁移的全部。 基于以上分析,对我来说svn2git工具似乎比git svn clone
native命令更好。
翻译自: https://www.journaldev.com/10618/svn-to-git-migration-complete-tutorial
svn迁移到git