转自:http://blog.csdn.net/a5244491/article/details/44807937
版权声明:本文为博主原创文章,未经博主允许不得转载。
因为一些特殊原因,需要将公司原来的代码仓库从github移植到oschina上去,项目手工操作很麻烦。自己整理了一下,写了简单的几个脚本来处理了。
在这之前,必须先手动在新的Git仓库上把项目先建立好,否则是不会成功的。(也许有命令行方式,还请告知,我不会)
1 先建立个空的目录,用来down工程以及处理工程
$ mkdir migrate
2 cd migrate #进入目录
3 执行自己写的迁移工具
$ gitmigrate git@git.oschina.NET:a5244491/xxxx
若有多个工程可把所有工程的ssh git地址都写到文件中,然后一次性处理。
以下是gitmigrate.sh的代码,使用方法就是gitmigrate $原git仓库上某个项目的ssh地址
#!/usr/bin/env bash
# 1是源地址temp=1
name=${temp##*/} #截取 core-lib.git
#tar="git@git.oschina.net:a5244491/"$name
tar="https://git.oschina.Net/a5244491/"name #tar="git@code.csdn.net:lianyin2013/"name
name={name%.*} #截取 core-lib echo "-------------------------git migrate -------------------------" echo "-----from"1
echo "-----to " tarecho"−−−−−−−−−−−−−−−−−−−−−−−−−gitclone−−−−−−−−−−−−−−−−−−−−−−−−−"echo"−−−−−from"1
git clone 1echo"−−−−−−−−−−−−−−−−−−−−−−−−−finishclone−−−−−−−−−−−−−−−−−−−−−−−−−"echo"−−−−−−−−−−−−−−−−−−−−−−−−−changedir−−−−−−−−−−−−−−−−−−−−−−−−−"echo"−−−−−to"name
cd namegitbranchtrackecho"−−−−−−−−−−−−−−−−−−−−−−−−−finishbranchtrack−−−−−−−−−−−−−−−−−−−−−−−−−"echo"−−−−−−−−−−−−−−−−−−−−−−−−−listbranchtrack−−−−−−−−−−−−−−−−−−−−−−−−−"gitbranchecho"−−−−−−−−−−−−−−−−−−−−−−−−−changetonewrepo−−−−−−−−−−−−−−−−−−−−−−−−−"echo"−−−−−−"tar
git remote set-url origin $tar
echo "-------------------------git fetch all-------------------------"
#git fetch --all
echo "-------------------------tal all-------------------------"
git add .
git commit -m "migrate commit."
echo "-------------------------git push all branchs -------------------------"
git push --all
echo "-------------------------finish git push all branch -------------------------"
git remote -v
其中gitbranchtrack
代码如下
#!/usr/bin/env bash
echo "track all branchs exculde master and HEAD"
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
git branch --track {branch##*/}branch
done
git fetch --all
git pull --all
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sky-heaven/p/7047726.html,如需转载请自行联系原作者