我阅读了Git手册、常见问题解答、Git-SVN速成课程等,他们都解释了这一点和那一点,但你找不到像这样的简单说明:

SVN存储库位于:svn://myserver/path/to/svn/repos

Git存储库位于:git://myserver/path/to/git/repos

git-do-the-magic-svn-import-with-history \
svn://myserver/path/to/svn/repos \
git://myserver/path/to/git/repos

我不希望它这么简单,也不希望它是一个命令。但我确实希望它不要试图解释任何事情——只是说在这个例子中应该采取什么步骤。


当前回答

为此,我使用了svn2git库,过程如下:

sudo apt-get安装git-core git-svn-rubysudo gem安装svn2gitsvn log--quiet|grep-E“r[0-9]+\|.+\|”|cut-d'|'-f2|sed's///g'|sort|uniq>authors.txt(此命令用于映射作者)

以上步骤应该在要从svn转换为git的文件夹中执行。

在authors.txt中每行添加一个映射,如下所示

anand = Anand Tripathi <email_id>
trip = Tripathi Anand <email_id>

为新的git存储库创建一个文件夹,并执行以下命令,路径为authors.txt

svn2git <svn_repo_path> --nobranches --notags --notrunk --no-minimize-url --username <user_name> --verbose  --authors <author.txt_path>

If no trunk and no tag and branch is present then have to execute the above command else if root is trunk then mention rootistrunk or trunk is present then --trunk <trunk_name>

git远程添加原点git push—所有原点git push—标记原点

其他回答

只使用git、SVN和bash的稍微扩展的答案。它包括SVN存储库的步骤,这些存储库不使用带有主干/分支/标签目录布局的常规布局(SVN绝对不执行这种布局)。

首先使用此bash脚本扫描SVN repo以查找不同的贡献者,并为映射文件生成模板:

#!/usr/bin/env bash
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
  echo "${author} = NAME <USER@DOMAIN>";
done

使用此选项可以创建一个作者文件,在该文件中,您可以使用git-config财产user.name和user.email将svn用户名映射到开发人员设置的用户名和电子邮件(请注意,对于GitHub这样的服务,只有匹配的电子邮件就足够了)。

然后让git-svn将svn存储库克隆到git存储库,告诉它映射:

git-svn clone--authors file=authors--stdlayoutsvn://example.org/Folder/projectroot

这可能需要非常长的时间,因为git-svn将单独检查存在的每个标记或分支的每个修订。(请注意,SVN中的标记实际上只是分支,因此它们在Git中最终也是如此)。您可以通过删除SVN中不需要的旧标记和分支来加快速度。

在同一网络中的服务器上或同一服务器上运行它也可以真正加快速度。此外,如果由于某种原因,此过程中断,您可以使用

git-svn-rebase--继续

在很多情况下,你已经在这里完成了。但是,如果您的SVN回购有一个非传统的布局,您只需在SVN中有一个目录,就可以将其放入git分支中,那么您可以执行一些额外的步骤。

最简单的方法是在服务器上创建一个新的SVN repo,它遵循惯例,并使用SVN副本将目录放在主干或分支中。如果您的目录完全位于repo的根目录,这可能是唯一的方法,当我上次尝试这个git-svn时,它只是拒绝执行签出。

您也可以使用git执行此操作。对于git-svn克隆,只需使用您想要放入git分支的目录。

运行后

git branch --set-upstream master git-svn
git svn rebase

注意,这需要Git1.7或更高版本。

请参阅git-svn官方手册页。特别是,请查看“基本示例”:

跟踪和贡献整个Subversion管理的项目(完成具有主干、标签和分支):

# Clone a repo (like git clone):
    git svn clone http://svn.foo.org/project -T trunk -b branches -t tags

收回,收回

对于复杂的案件,埃里克·S·雷蒙德(Eric S.Raymond)的收回是首选工具。除了SVN,它还通过快速导出格式和CVS支持许多其他版本控制系统。作者报告了Emacs和FreeBSD等古代存储库的成功转换。

该工具显然旨在实现近乎完美的转换(例如将SVN的SVN:ignore财产转换为.gitignore文件),即使是对于历史悠久的复杂存储库布局也是如此。在许多情况下,其他工具可能更容易使用。

在深入研究repourgeon命令行的文档之前,请务必阅读出色的DVCS迁移指南,该指南将逐步介绍转换过程。

我在一台windows机器上,通过调用

传输.bathttp://svn.my.address/svn/myrepo/trunk https://git.my.address/orga/myrepo

也许任何人都可以使用它。它创建了一个TMP文件夹,用git签出SVN repo,添加新的来源并推送它……然后再次删除文件夹。

@echo off 
SET FROM=%1 
SET TO=%2 
SET TMP=tmp_%random%

echo from:  %FROM% 
echo to:    %TO% 
echo tmp:   %TMP%

pause

git svn clone  --no-metadata --authors-file=users.txt %FROM% %TMP%  
cd %TMP% 
git remote add origin %TO% 
git push --set-upstream origin master


cd .. 
echo delete %TMP% ... 
pause

rmdir /s /q %TMP%

您仍然需要users.txt和用户映射,如

User1 = User One <u.1@xxx.com>

用于SVN到GIT迁移的一体式shell脚本。用占位符提及GIT和SVN详细信息

#!/bin/bash

######## Project name 
PROJECT_NAME="Helloworld"
EMAIL="example mail"

#Credientials Repo
GIT_USER='<git username>'
GIT_PWD='<git password>'
SVN_USER='<svn username>'
SVN_PWD='<svn password>'

######## SVN repository to be migrated # Dont use https - error will be thrown
BASE_SVN="<SVN URL>/Helloworld"

#Organization inside BASE_SVN
BRANCHES="branches"
TAGS="tags"
TRUNK="trunk"

#Credientials
git config --global user.name '<git username>'
git config --global user.password '<git password>'
git config --global credential.helper 'cache --timeout=3600'

######## GIT repository to migrate - Ensure already project created in Git
GIT_URL=https://$GIT_USER:$GIT_PWD@<GIT URL>/Helloworld.git

###########################
#### Don't need to change from here
###########################

#Geral Configuration
ABSOLUTE_PATH=$(pwd)
TMP=$ABSOLUTE_PATH/$PROJECT_NAME

#Branchs Configuration
SVN_BRANCHES=$BASE_SVN/$BRANCHES
SVN_TAGS=$BASE_SVN/$TAGS
SVN_TRUNK=$BASE_SVN/$TRUNK

AUTHORS=$PROJECT_NAME"-authors.txt"

echo '[LOG] Starting migration of '$SVN_TRUNK
echo '[LOG] Using: '$(git --version)
echo '[LOG] Using: '$(svn --version | grep svn,)

mkdir $TMP
echo
echo '[DIR] cd' $TMP
cd $TMP

echo
echo '[LOG] Getting authors'
svn --username $SVN_USER --password $SVN_PWD log -q $BASE_SVN | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2"@"$EMAIL">"}' | sort -u >> $AUTHORS

echo
echo '[RUN] git svn clone --authors-file='$AUTHORS' --trunk='$TRUNK' --branches='$BRANCHES' --tags='$TAGS $BASE_SVN $TMP
git svn clone --authors-file=$AUTHORS --trunk=$TRUNK --branches=$BRANCHES --tags=$TAGS $BASE_SVN $TMP

#Not working so no need to mention it
#--stdlayout $PROJECT_NAME
echo
echo '[RUN] svn ls '$SVN_BRANCHES
svn ls $SVN_BRANCHES

echo 
echo 'git branch -a'
git branch -a

echo
echo '[LOG] Getting first revision'
FIRST_REVISION=$( svn log -r 1:HEAD --limit 1 $BASE_SVN | awk -F '|' '/^r/ {sub("^ ", "", $1); sub(" $", "", $1); print $1}' )

echo
echo '[RUN] git svn fetch -'$FIRST_REVISION':HEAD'
git svn fetch -$FIRST_REVISION:HEAD

#Branches and Tags  
echo
echo '[RUN] svn ls '$SVN_BRANCHES
for BRANCH in $(svn ls $SVN_BRANCHES); do
    echo git branch ${BRANCH%/} remotes/svn/${BRANCH%/}
    git branch ${BRANCH%/} remotes/svn/${BRANCH%/}
done

git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/origin/tags | grep -v "@" | cut -d / -f 3- |
while read ref
do
  echo git tag -a $ref -m 'import tag from svn'
  git tag -a $ref -m 'import tag from svn'
done

git for-each-ref --format="%(refname:short)" refs/remotes/origin/tags | cut -d / -f 1- |
while read ref
do
  git branch -rd $ref
done
  
echo
echo 'git tag'
git tag

echo
echo 'git show-ref --tags'
git show-ref --tags

echo
echo '[RUN] git remote add origin '$GIT_URL
git remote add origin $GIT_URL

echo
echo '[RUN] git push'
git push origin --all --force
git push origin --tags

#echo git branch -d -r trunk
#git branch -d -r trunk

git config --global credential.helper cache
echo 'Successful.'

当您运行上述脚本时,它将从SVN中获取分支和标记详细信息,并将其放在.git文件夹下。交叉检查SVN中是否存在所有分支,这些分支应在此.git/refs/heads文件夹下可用。如果SVN中缺少一些分支,请手动将分支文件从.git/refs/remotes/origin/<branches>复制到.git/refs/heads只复制分支(包括主分支),如果有标记或主干,则忽略。现在再次运行脚本。您可以在git存储库中看到所有分支和标记。