第一步:
安装 svn2git  : sudo apt-get install svn2git

git svn fetch –authors-file=userinfo.txt

git svn init svn+ssh://svn@10.20.30.18/svn-repos/mtk6735m-aly/ –no-metadata –trunk=trunk-android/pb3.2.0/ –branches=branches/ –branches=branches-android/ –branches=trunk/ gitproject

第一步:创建裸库
git init –bare
第二步 : 添加远程git服务器地址(从svn转git的库,指向裸库),即裸库视为原始库的服务器
git remote add origin file:///home/topwise/zyfcode/new-mtk6735m-aly
第三步:创建新分支跟踪远程分支(在svn转git的库上做,即原始库上做)
vim .git/config 查看远程分支信息
git log –graph –decorate 查看log : 当前分支指向
git log –graph remotes/branches-android/pb3.2.0 查看log
git branch trunk-pb3.2.0 remotes/trunk/pb3.2.0 创建新分支跟踪远程分支
第四步:推送全部的分支到git服务器上
git push –all origin

git push origin local_branch:remote_branch

这个操作,local_branch必须为你本地存在的分支,remote_branch为远程分支,如果remote_branch不存在则会自动创建分支。

类似,git push origin :remote_branch,local_branch留空的话则是删除远程remote_branch分支。

脚本:
1、cherry-pick.sh 用于将需要批量处理的commit逐个cherrypick,失败的commit记录下来,跳过。

*************************************

!/bin/bash

用于批量处理cherry-pick

参数说明:1commit列表;<script id="MathJax-Element-1" type="math/tex">{1} commit 列表 ; </script>{2} 为输出信息 ; ${3} temp file

echo 1>><script id="MathJax-Element-2" type="math/tex">{1} >> </script>{2}
echo ‘执行开始’ >> ${2}
i=0
for line in tac ${1}
do
cmdstr=cat cmd.txt
if [ -n “${cmdstr}” ]
then
break
fi

不是合法的commit id,跳过

sha1=echo "${line}" | grep -E "^[a-f0-9]+$"
echo —— sha1−−−−−−<script id="MathJax-Element-3" type="math/tex">{sha1} ------ </script>{line}
if [ -z “${sha1}” ]
then
continue
fi

((i=i+1))echo……………………………..<script id="MathJax-Element-4" type="math/tex">i+1)) echo ……………………………..</script>{i}......................................................... >> 2echo<script id="MathJax-Element-5" type="math/tex">{2} echo </script>{line} start >> 2gitcherry−pick<script id="MathJax-Element-6" type="math/tex">{2} git cherry-pick </script>line 2> 3if[<script id="MathJax-Element-7" type="math/tex">{3} if [ </script>? -ne 0 ]
then

过滤merge 的 commit

#slog=`git log $line --oneline | grep "^[a-f0-9]* Merge "`
    slog=`git show $line --oneline --summary | grep "^[a-f0-9]* Merge "`
if [ -z "${slog}" ]
then
        info=`cat ${3} | grep "git commit --allow-empty"`
    if [ -z "${info}" ]
    then
        errinfo=`cat ${3} | grep "Aborting commit due to empty commit message"`
        if [ -z "${errinfo}" ]
         then
         #output erroinfo
         allerrorinfo=`cat ${3}`
         echo ${allerrorinfo} >> ${2}
         sed -i "s/^${line}/error_${line}/" "${1}"
         git cherry-pick --abort
         else
         sed -i "s/^${line}/empty_message_${line}/" "${1}"
         git commit --allow-empty-message --no-edit
        fi
    else
         sed -i "s/^${line}/empty_${line}/" "${1}"
         git commit --allow-empty --no-edit
    fi
else
    sed -i "s/^${line}/merge_${line}/" "${1}"   
fi
 else
        sed -i "s/^${line}/ok_${line}/" "${1}"
 fi 
echo ${line} end >> ${2}

done
echo ……………………………………………………………………………….. >> ${2}
echo ‘执行完毕’
read yourcomd
*************************************

2、cherry-pick–edit.sh 这个脚本用于将上面脚本自动处理不了的commit,逐个cherrypick ,有人工介于的机会。

*************************************

!/bin/bash

用于批量处理cherry-pick

参数说明:1commit列表;<script id="MathJax-Element-8" type="math/tex">{1} commit 列表 ; </script>{2} 为输出信息 ; ${3} temp file

echo 1>><script id="MathJax-Element-9" type="math/tex">{1} >> </script>{2}
echo ‘执行开始’ >> ${2}
i=0
for line in tac ${1}
do
((i=i+1))echoaaaaaaaaaaaaaaaaaaaaaaaaa<script id="MathJax-Element-10" type="math/tex">i+1)) echo aaaaaaaaaaaaaaaaaaaaaaaaa </script>{i} aaaaaaaaaaaaaaaaaaaaaaaaaaaa
echo …………… ${line} start ………………

sha1=`echo  "${line}"  | grep -E  "^[a-f0-9]+$"`   
echo ------ ${sha1} ------ ${line} 
  if [ -z "${sha1}" ]
    then
    continue
    fi
git cherry-pick $line 2> ${3}
 #git cherry-pick $line 2>&1 | tee ${3}
 if [ $? -ne 0 ]
then

过滤merge 的 commit

cat ${3}
#slog=`git log ${3} --oneline | grep "^[a-f0-9]* Merge "`
slog=`git show $line --oneline --summary | grep "^[a-f0-9]* Merge "`
if [ -z "${slog}" ]
then
        info=`cat ${3} | grep "git commit --allow-empty"`
    if [ -z "${info}" ]
    then
        errinfo=`cat ${3} | grep "Aborting commit due to empty commit message"`
        if [ -z "${errinfo}" ]
         then
         #output erroinfo
         allerrorinfo=`cat ${3}`
         #echo ${allerrorinfo} 
         sed -i "s/^${line}/proc_${line}/" "${1}"
         break
        #if [ ${yourcmd} = "continue" ]
        #then
        #echo ${line} continue
        #fi
        #if [ ${yourcmd} = "break" ]
        #then
        #break;
        #fi
         else
         sed -i "s/^${line}/empty_message_${line}/" "${1}"
         git commit --allow-empty-message --no-edit
        fi
    else
         sed -i "s/^${line}/empty_${line}/" "${1}"
         git commit --allow-empty --no-edit
    fi
else
    sed -i "s/^${line}/merge_${line}/" "${1}"   
fi
 else
        sed -i "s/^${line}/ok_${line}/" "${1}"
 fi 
echo ............. ${line} end ...............

done

*************************************

3、getsha1.sh 将 git log –oneline提取的commit信息列表中,提取sha1值。
*************************************

!/bin/bash

用于将在log中截取sha1值 ; 参数说明 : ${1} 为需要处理的文件名

sed -i “s/(^[a-f0-9]) ./\1/” ${1}
*************************************

4、del_sha1.sh 将不需要cherry pick的commit列表,从目录列表中清除
*************************************

!/bin/bash

用于处理git cherry-pick的commit列表,将需要删除的commit删除掉

参数说明 : 1为需要删除的commit列表;<script id="MathJax-Element-11" type="math/tex">{1} 为需要删除的commit列表 ; </script>{2} 待处理cherry-pick的commit列表的文件(目标处理文件)

echo 1echo<script id="MathJax-Element-12" type="math/tex">{1} echo </script>{2}
i=0
strfind=””
for line in cat ${1}
do
((i=$i+1))

strfind=”line”echo“line(<script id="MathJax-Element-13" type="math/tex">{line}” echo “line (</script>i):" "strfind”  
sed -i “/^
<script id="MathJax-Element-14" type="math/tex">strfind” sed -i “/^</script>{strfind}/d" "${2}”
done
*************************************

5、del_line_startwith.sh
*************************************

!/bin/bash

用于将以${1} 开始的行删除

参数说明 : 1指定的字符串前缀;<script id="MathJax-Element-18" type="math/tex">{1} 指定的字符串前缀 ; </script>{2} 待处理的文件(目标处理文件)

echo 1echo<script id="MathJax-Element-19" type="math/tex">{1} echo </script>{2}
sed -i “/^1/d""<script id="MathJax-Element-20" type="math/tex">{1}/d" "</script>{2}”
*************************************

svn log –xml file:///home/svn-repos/mtk6735m-kk-aly/ | grep /author | sort -u | awk -F ‘[

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐