Git仓库的选取以及迁移

前文我展示了一个关于Debian系统配置的脚本,而新装电脑除了配置之外还有一个问题就是……资源的迁移!(对于一般的资源可以使用scp拷贝,当然在局域网内scp的速度相当可观,但是对于git仓库这样的特殊资源,直接使用scp可能会影响git仓库的使用哦!)

我个人的习惯时将所有的git仓库都放在一个叫做repository的目录下。如果通过一个个检查该目录下dirs/.git/config下的地址,然后一条条git clone 来在另一台机器上重建仓库目录显得有点太不专业了,所以我写了个非常简单的脚本(my_repository.sh)读取仓库中的地址,并把所有地址都追加到一个文件中,然后使用另外一个脚本(clone.sh)对这个文件中所有的地址进行git clone ,很简单。

首先,看一下搜集git仓库地址的shell脚本:

#!/bin/bash# (C) 2014 Yunlong Zhou <reaper888@yeah.net># Under licence GPL# File : my_repository.sh # Introduction:# This script is using for collect all the git address to a file — repository_file# Useage :# 1. cd repository– cd to the dir that you store all the git repository# 2. chmox +x my_repository.sh– give the script a execute permission# 3. ./my_repository.sh

# for delete old temp file ,if there is !if [ -f all_dir -a -f repository_file ]; thenecho “Now delete old temp file”rm all_dir repository_file 2> /dev/nullfi

# read all the items under this dir to the file all_dirls -l | awk ‘{print $9}’ > all_dir# deal with every git repository dir and collect the url then store to file repository_filewhile read FILE_NAMEdoif [ $FILE_NAME != ” ” -a -d $FILE_NAME -a -s $FILE_NAME ];then echo “Now dealing the “$FILE_NAME if [ -d $FILE_NAME/.git ]; then grep -e “url”$FILE_NAME/.git/config | cut -d “=” -f2 | cut -d ” ” -f2 >>repository_file fifi

done < all_dir# remove temp file and give a Hint !rm all_dirif [ $? == 0 ]; thenecho “Ok,all the url of your repository have been send to file — repository_file”fi

现在,所有仓库目录下的git仓库地址已经被添加到repository_file文件中,如:

linuxidc.com@zhouyl:~/repository$ cat repository_filegit://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.gitgit://gitorious.org/tinylab/pleac-shell.gitgit://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git…这里省略了十几个个人仓库

现在我们可以使用scp将repository_file文件以及对下面的这个脚本拷贝到新安装的电脑上(scp repository_file clone.sh linuxidc.com@192.168.2.110:/tmp/),,然后直接运行clone.sh(./clone.sh)即可!

#!/bin/bash# (C) 2014 Yunlong Zhou <reaper888@yeah.net># Under licence GPL# File : clone.sh # Introduction:# This script is using for git clone every item in repository_file# Useage :# 1. ./clone.sh

if [ ! -f repository_file ]; thenecho “There is no repository_file ,we will exit”exitfi

while read READLINEdoecho “Now we will clone $READLINE”git clone $READLINEdone < repository_file

rm repository_file

Git 的详细介绍:请点这里Git 的下载地址:请点这里

推荐阅读:

Fedora通过Http Proxy下载Git

在Ubuntu Server上安装Git

服务器端Git仓库的创建(Ubuntu)

Linux下Git简单使用教程(以Android为例)

Git权威指南 PDF高清中文版

快乐要懂得分享,才能加倍的快乐

Git仓库的选取以及迁移

相关文章:

你感兴趣的文章:

标签云: