手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Git仓库的选取以及迁移

[日期:2014-03-10] 来源:Linux社区  作者:longerzone [字体:大 中 小]

前文我展示了一个关于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 ]; then
 echo "Now delete old temp file" 
 rm all_dir repository_file 2> /dev/null
fi

# read all the items under this dir to the file all_dir
ls -l | awk '{print $9}' > all_dir
# deal with every git repository dir and collect the url then store to file repository_file
while read FILE_NAME
do
 if [ $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
  fi
 fi

done < all_dir
# remove temp file and give a Hint !
rm all_dir
if [ $? == 0 ]; then
 echo "Ok,all the url of your repository have been send to file -- repository_file"
fi

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

linuxidc.com@zhouyl:~/repository$ cat repository_file
git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
git://gitorious.org/tinylab/pleac-shell.git
git://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 ]; then
 echo "There is no repository_file ,we will exit"
 exit
fi

while read READLINE
do
 echo "Now we will clone $READLINE"
 git clone $READLINE
done < repository_file

rm repository_file

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

推荐阅读:

Fedora通过Http Proxy下载Git http://www.linuxidc.com/Linux/2009-12/23170.htm

在Ubuntu Server上安装Git http://www.linuxidc.com/Linux/2009-06/20421.htm

服务器端Git仓库的创建(Ubuntu) http://www.linuxidc.com/Linux/2011-02/32542.htm

Linux下Git简单使用教程(以Android为例) http://www.linuxidc.com/Linux/2010-11/29883.htm

Git权威指南 PDF高清中文版 http://www.linuxidc.com/Linux/2013-10/91053.htm

linux
相关资讯       Git  Git仓库 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款