用shell脚本生成path

Git 一键生成补丁 old folder new folder update.path 
原理很简单,看下面脚本,使用也很简单

$ git log
commit 75df2c656ba0ff4654515922f1d26c102577c9e6
Author: DevinLow <[email protected]>
Date:   Thu Sep 29 15:21:39 2016 +0800

    usb 去抖

commit e46d98b2818121b3639bc8a6cab0258581c513aa
Author: DevinLow <[email protected]>
Date:   Thu Sep 29 15:01:09 2016 +0800

    init project

往下是生成path的shell脚本
$./gitdiff.sh  e46d98b28181...   75df2c656ba..... 
Archive:  new.zip
75df2c656ba0ff4654515922f1d26c102577c9e6
   creating: ./new/mediatek/
   creating: ./new/mediatek/kernel/
   creating: ./new/mediatek/kernel/drivers/
   creating: ./new/mediatek/kernel/drivers/usb20/
  inflating: ./new/mediatek/kernel/drivers/usb20/musb_core.c  
Archive:  old.zip
e46d98b2818121b3639bc8a6cab0258581c513aa
   creating: ./old/mediatek/
   creating: ./old/mediatek/kernel/
   creating: ./old/mediatek/kernel/drivers/
   creating: ./old/mediatek/kernel/drivers/usb20/
  inflating: ./old/mediatek/kernel/drivers/usb20/musb_core.c  
liugang@ospicon-ubuntu:~/8127_mlc_kk$ 
在上一层的目录中就会生成 update目录
$ ls  ../update/ -l
ls: 初始化月份字符串出错
总用量 12
drwxrwxr-x 3 liugang liugang 4096  99 18:55 new
drwxrwxr-x 3 liugang liugang 4096  99 18:55 old
-rw-rw-r-- 1 liugang liugang 1031  99 18:55 update.path

生成path的具体shell脚本内容

#!/bin/bash
targetfolder=../update
targetname=update.zip
if [ $# != 2 ] ; then
        echo "USAGE: $0 OLD_ID NEW_ID" 
        exit 1;
fi
mkdir -p $targetfolder
git diff $1 $2 >../update/update.path
git archive -o ../update/new.zip $2 $(git diff --name-only $1 $2)  #新版本的差异文件
git archive -o ../update/old.zip $1 $(git diff --name-only $2 $1)  #旧版本的差异文件
cd ../update
unzip -o -d ./new/ new.zip
unzip -o -d ./old/ old.zip
rm new.zip old.zip

猜你喜欢

转载自blog.csdn.net/sdkdlwk/article/details/82888363