使用 git 将两个不同 branch 以差分包形式生成补丁

使用 git 将两个不同 branch 以差分包形式生成补丁

#!/bin/bash
#  
# Usage:
# ./run_script.sh old_branch new_branch
# ./run_script.sh old_commit new_commit
# Before running the script, you must commit what you have modified.
# After the script is done, you should checkout back to the branch you use.

dt=$(date +%Y%m%d)
# SET the temp path:
FN="/home/nick/tmp/$dt"
# SET the git path:
gitpath='/home/nick/rockchip/box_4.4.2_0519/' 
if [ $# -eq 2  ];then
    cd $gitpath
    #1 find out the diff file name:
    git diff $1 $2 --name-only > $FN.txt
    #2 del last line:
    #sed -i '$d' $FN.txt
    target="/home/nick/tmp/diff_$1_$2_$dt"
    # Make the target directory:
    mkdir $target
    #3 switch to new branch:
    git checkout $2
    #4 export the new files:
    /usr/bin/rsync -rltDv --files-from=$FN.txt $gitpath $target/new
    #5 switch to old branch:
    git checkout $1
    #6 export the old files:
    /usr/bin/rsync -rltDv --files-from=$FN.txt $gitpath $target/old

    ### tar as a tar.gz file.
    tar -czPf $target/code_$1_$2_$dt.tar.gz  $target
    echo "tar ok!"; 
else 
echo "Usage:
    ./run_script.sh old_branch new_branch
    ./run_script.sh old_commit new_commit
Note:
    Before running the script, you must commit what you have modified.
    After the script is done, you should checkout back to the branch you use.
    "
fi
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值