歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Git倉庫的選取以及遷移

Git倉庫的選取以及遷移

日期:2017/2/28 14:35:14   编辑:Linux教程

前文我展示了一個關於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 <[email protected]>
# 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 [email protected]:/tmp/),然後直接運行clone.sh(./clone.sh)即可!

#!/bin/bash
# (C) 2014 Yunlong Zhou <[email protected]>
# 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

Copyright © Linux教程網 All Rights Reserved