我阅读了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

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


当前回答

atlassian网站上的这份指南是我找到的最好的指南之一:

https://www.atlassian.com/git/migration

此工具-https://bitbucket.org/atlassian/svn-migration-scripts-对于生成authors.txt等内容也非常有用。

其他回答

TortoiseGit这样做。查看此日志:http://jimmykeen.net/articles/03-nov-2012/how-migrate-from-svn-to-git-windows-using-tortoise-clients

是的,我知道用链接回答不是很好,但这是一个解决方案,嗯?

只使用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或更高版本。

实现这一目标有不同的方法。我尝试了其中的一些,发现在Windows操作系统上只安装了git和svn就可以了。

前提条件:

windows上的git(我用过这个)https://git-scm.com/ 安装了控制台工具的svn(我使用过乌龟svn)转储SVN存储库的文件。svnadmin转储/path/to/repository>repo_name.svn_dump

实现最终目标的步骤(将所有具有历史记录的存储库移动到git,首先是本地git,然后是远程git)

在REPO_NAME_FOLDER目录中创建空存储库(使用控制台工具或tortoiseSVN)cd REPO_NAME_PARENT_FOLDER,将dumpfile.dump放入REPO_NAME_PARENT_FOLDsvnadmin load REPO_NAME_FOLDER<dumpfile.dump等待此操作,可能需要很长时间此命令是无声的,因此打开第二个cmd窗口:svnserve-d-R--root REPO_NAME_FOLDER为什么不直接使用file:///...... ? 因为下一个命令将失败,无法打开。。。到URL:,感谢您的回答https://stackoverflow.com/a/6300968/4953065创建新文件夹SOURCE_GIT_foldercd源_GIT_FOLDERgit-svn克隆svn://localhost/等待此操作。

最后,我们得到了什么?

让我们查看本地存储库:

git log

看到您以前的提交吗?如果是-好

现在,您已经拥有了功能齐全的本地git存储库,其中包含您的源代码和旧svn历史记录。现在,如果要将其移动到某个服务器,请使用以下命令:

git remote add origin https://fullurlpathtoyourrepo/reponame.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

在我的情况下,我不需要标签命令,因为我的repo没有标签。

祝你好运

用于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存储库中看到所有分支和标记。

将svn子模块/文件夹“MyModule”转换为具有历史记录的git,既没有标记也没有分支。

git-svn clone--无元数据--trunk=SomeFolder1/SomeFolder2/SomeFolder3/MyModulehttp://svnhost:port/repo_root_folder/MyModule_temp-一个C: \ccheetah\svn\authors-transform.txtgit克隆MyModule_temp MyModulecd我的模块git流初始化git远程设置url源https://userid@stashhost/stash/scm/xyzxyz/MyModule.gitgit push-u原始主机gitpush-u源代码开发

要保留svn忽略列表,请在步骤1之后使用以上注释