前提

Linux 环境
安装 git 、svn 、git-svn

步骤

  1. 创建用户映射
    例如:

    zhangsan = zhangsan <[email protected]>
    lisi = lisi <[email protected]>
    

    如何获取 作者列表 ?
    在 svn 库下执行当前命令 生成 users.txt,获得 svn 作者列表:

    svn log ^/ --xml | grep -P "^<author" | sort -u | perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt
    
  2. SVN 转到本地 git 仓库
    通过 git svn clone 命令可以把整个 SVN 仓库导入到一个本地的 git 仓库中, 但这样导入的代码提交历史很糟糕, 需要做一些处理. 在 clone 后面添加 –no-metadata 来阻止 git svn 包含那些 SVN 的附加信息。同时为了获得更精确的提交者 ID 和邮箱, 添加 –authors-file 参数

    git svn clone svn://ip端口/projectname --no-metadata --authors-file=users.txt projectname
    cd projectname
    
    

    实操:

    git svn clone https://172.16.19.89/svn/Android/branches/face_mipi_tj_bjvigilante_hotel --no-metadata --authors-file=users.txt ZhiZongFaceOne
    

    git 03 | svn 转 git and 修改 git commit 邮箱

  3. 修改 .gitignore 上传到自己的 remote 仓库

$ git rm -r --cached .
$ git add .gitignore
$ git commit -m " update .gitignore"

修改 git commit email

修改所有分枝的一个用户名

#!/bin/sh
  
git filter-branch -f --env-filter '

OLD_EMAIL="[email protected]"
CORRECT_NAME="zhangyingjie"
CORRECT_EMAIL="[email protected]"
 
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

修改多个用户名,失败,后续研究

失败代码,读取 usersName.txt 每行,然后执行 此代码,代码的 变量传递打印结果正确,但是执行到最后,commit email 没有更改。

#!/bin/sh

cat usersName.txt | while read myLine;
 do 
 # echo $line 
 export line=${myLine}
	git filter-branch -f --env-filter '

OLD_EMAIL="${line}@beeboxes.net".
CORRECT_NAME=${line}
CORRECT_EMAIL="${line}@company.com"
 echo $OLD_EMAIL  $CORRECT_NAME  $CORRECT_EMAIL

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

 done

参考文章:https://blog.csdn.net/Hello_Mr_Cc/article/details/72742503

相关文章:

  • 2021-07-11
  • 2021-04-30
  • 2022-02-08
  • 2022-12-23
  • 2021-11-09
  • 2021-10-13
  • 2021-04-25
猜你喜欢
  • 2022-03-03
  • 2022-03-06
  • 2021-09-14
  • 2021-06-13
  • 2021-08-10
  • 2021-06-16
  • 2021-07-16
相关资源
相似解决方案