我们可以使用git-svnclone命令,如下所示。
svn log-q<svn_URL>|awk-F'|''/^r/{sub(“^”,“”,$2);sub(”$“,”,$2);print$2“=”$2“<”$2”>“}'|sort-u>authors.txt
上述命令将从SVN提交创建authors文件。
svn日志—复制时停止<svn_URL>
创建SVN项目时,上面的命令将为您提供第一个修订号。
git svn clone-r<svn_REV_NO>:HEAD--无最小化url--stdlayout--无元数据--作者文件authors.txt<svn_url>
以上命令将在本地创建Git存储库。
问题是它不会将分支和标签转换为推送。您必须手动执行这些操作。以下分支机构示例:
$ git remote add origin https://github.com/pankaj0323/JDProjects.git
$ git branch -a
* master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$$ git checkout -b MyDevBranch origin/MyDevBranch
Branch MyDevBranch set up to track remote branch MyDevBranch from origin.
Switched to a new branch 'MyDevBranch'
$ git branch -a
* MyDevBranch
master
remotes/origin/MyDevBranch
remotes/origin/tags/MyDevBranch-1.0
remotes/origin/trunk
$
对于标记:
$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
$
现在将master、branches和标记推送到远程git存储库。
$ 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
$
svn2git实用程序
svn2git实用程序删除了带有分支和标记的手动工作。
使用命令sudogeminstallsvn2git安装它。之后运行以下命令。
$svn2git<SVN_URL>--authors.txt--修订版<SVN_REV_NO>
现在,您可以列出分支、标记并轻松推送它们。
$ 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
假设您有20个分支和标记,显然svn2git将为您节省大量时间,这就是为什么我比原生命令更喜欢它的原因。这是一个很好的原生git-svnclone命令包装器。
有关完整的示例,请参阅我的博客条目。