git备份代码
Posted smlile-you-me
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git备份代码相关的知识,希望对你有一定的参考价值。
仓库备份位置: /huawei-bak
vim /huawei-bak/huawei-bak.sh
#!/bin/bash
#项目克隆下来后将其注释即可
PROJECT="
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]:xxxx.git
[email protected]:xxxx.git
"
for i in $PROJECT
do
git clone $PROJECT
done
#以下为备份代码
cd /huawei-bak
ls -l |grep ^d|awk -F ‘ ‘ ‘{print $9}‘|grep -v bak$ >> 1.txt
cat 1.txt | while read Dir
do
cd $Dir
/usr/local/git/bin/git fetch origin #更新本地的远程分支
/usr/local/git/bin/git diff --stat master origin/master | grep "changed" #统计文件的改动
if [ $? -eq 0 ];then
echo "--------------------------------------------">>../huawei-bak.log
echo "项目名称: $Dir">>../huawei-bak.log
echo "同步时间: `date +‘%F %T‘`">>../huawei-bak.log
/usr/local/git/bin/git pull >>../huawei-bak.log
/usr/local/git/bin/git fetch --all #取远程所有分支到本地(是所有)
fi
cd ../
done
rm -rf 1.txt
以上是关于git备份代码的主要内容,如果未能解决你的问题,请参考以下文章