傻瓜式同步svn到git
$SoucePath = Read-Host "请输入仓库目录,可空";
$firstTimeDir = Read-Host "请输入项目名称,可空";
$SvnAddress = Read-Host "请输入Svn地址,可空";
$GitAddress = Read-Host "请输入Git地址,可空";
# 记录当前脚本目录
$pspath=pwd;
if($SvnAddress -eq $null -or $SvnAddress -eq "" -or $GitAddress -eq $null -or $GitAddress -eq "")
{
echo "sync svn to git.";
if($SoucePath -eq $null -or $SoucePath -eq "")
{
throw "[-SoucePath] can not be empty.";
}
# 进入源码目录
pushd $SoucePath;
# 如果 local-git-svn 分支存在才执行这条命令
git branch -d local-git-svn;
# 创建分支并切换到 local-git-svn
git checkout -b local-git-svn refs/remotes/git-svn;
# 拉取SVN最新修改代码
git svn fetch;
# 切换回主分支
git checkout master;
# 再删除分支 local-git-svn
git branch -d local-git-svn;
# 再重写创建分支并切换到 local-git-svn
git checkout -b local-git-svn refs/remotes/git-svn;
# 切换回主分支
git checkout master;
# 合并最新代码到 master 分支
git merge local-git-svn;
# 推送到远程
git push -u origin master -f;
}
else
{
write-warning "The first time sync svn to git.";
if($firstTimeDir -eq $null -or $firstTimeDir -eq "")
{
throw "[-firstTimeDir] can not be empty.";
}
if($SvnAddress -eq $null -or $SvnAddress -eq "")
{
throw "[-SvnAddress] can not be empty.";
}
if($GitAddress -eq $null -or $GitAddress -eq "")
{
throw "[-GitAddress] can not be empty.";
}
# 克隆svn项目
git svn clone $SvnAddress --no-metadata --no-minimize-url --no-minimize-url $firstTimeDir;
pushd "./$firstTimeDir";
git init;
# 添加远程git地址
git remote add origin $GitAddress;
# 提交到git
git push -u origin master -f;
}
# 回到脚本目录
pushd $pspath;
首次将svn转git
& "./svntogit.ps1"
如果您觉得本文对你有用,不妨帮忙点个赞,或者在评论里给我一句赞美,小小成就都是今后继续为大家编写优质文章的动力,百小僧拜谢!
欢迎您持续关注我的博客:)
版权所有,欢迎保留原文链接进行转载:)