我阅读了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
我不希望它这么简单,也不希望它是一个命令。但我确实希望它不要试图解释任何事情——只是说在这个例子中应该采取什么步骤。
我使用以下脚本读取了一个包含所有SVN存储库列表的文本文件,并将其转换为Git,然后使用gitclone--bare将其转换成Git存储库:
#!/bin/bash
file="list.txt"
while IFS= read -r repo_name
do
printf '%s\n' "$repo_name"
sudo git svn clone --shared --preserve-empty-dirs --authors-file=users.txt file:///programs/svn/$repo_name
sudo git clone --bare /programs/git/$repo_name $repo_name.git
sudo chown -R www-data:www-data $repo_name.git
sudo rm -rf $repo_name
done <"$file"
list.txt的格式为:
repo1_name
repo2_name
users.txt的格式为:
(无作者)=罗杰斯王子<prince.rogers.nelson@payesley.park.org>
www数据是Apache web服务器用户,需要权限才能通过HTTP推送更改。
我只是想把我的贡献加入Git社区。我编写了一个简单的bash脚本,可以自动完成整个导入。与其他迁移工具不同,该工具依赖于原生git而不是jGit。该工具还支持具有较大修订历史和/或较大Blob的存储库。可通过github获得:
https://github.com/onepremise/SGMS
此脚本将以以下格式转换存储在SVN中的项目:
/trunk
/Project1
/Project2
/branches
/Project1
/Project2
/tags
/Project1
/Project2
该方案也很受欢迎和支持:
/Project1
/trunk
/branches
/tags
/Project2
/trunk
/branches
/tags
每个项目将按项目名称同步:
Ex: ./migration https://svnurl.com/basepath project1
如果要转换完整回购,请使用以下语法:
Ex: ./migration https://svnurl.com/basepath .
为此,我使用了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—标记原点
如果您正在使用SourceTree,则可以直接从应用程序执行此操作。转到文件->新建/克隆,然后执行以下操作:
输入远程SVN URL作为“源路径/URL”。在提示时输入凭据。输入本地文件夹位置作为“目标路径”。给它起个名字。在高级选项中,从“创建本地”下拉列表中选择“Git”类型的存储库”。您可以选择指定要从中克隆的修订。点击克隆。
在SourceTree中打开回购,您将看到您的提交消息也已迁移。
现在转到存储库->存储库设置并添加新的远程存储库详细信息。如果您愿意,请删除SVN远程(我通过“编辑配置文件”选项执行此操作)。
准备好后,将代码推送到新的远程存储库,并自由编码。
用于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存储库中看到所有分支和标记。