Git导出差分(diff)包--before/after/patch

*完全由本人原创,转载请注明出处哦~
http://blog.youkuaiyun.com/adrianjian/article/details/44085181*

差分包是什么?

即修正前后的差异。包含修正前、后文件目录,和由git diff [-b]生成的差分文件。

  • before: 包含本次修正中,被修改和删除的文件。
  • after: 包含被修改和新增的文件。
  • patch: 差分文件。

为何要导出差分包?

主要目的是与其他的版本控制系统的互操作。

  • 将修正应用到其他CVS,不管该CVS是否可以apply patch
  • 利用其他文件对比工具分析代码修改情况
  • 作为代码评审时的材料

如何导出?

利用以下shell脚本生成。需要系统中安装Git

diffex.sh

#!/bin/bash 

FORCE=n
QUIET=n
BINARY=n
BRANCH=
TARGET=".diffdir"
CURRENT_BRANCH=

# Tell the usage of this script.
# no parameters.
usage()
{
    echo "Usage: `basename $0` [-nqf] [-t TARGET] -b BRANCH"
    echo "  -n  set to output binary diff."
    echo "  -q  quiet mode, minimal messges."
    echo "  -f  force mode, none confirmation."
    echo "  -t  output target directory."
    echo "  -b  the base branch to diff from."
    exit 1
}

# Check whether the current directory is a git repository.
# no parameters.
isrepo()
{
    status=`git status -s`;
    if [ ! -z "$status" ]; then
        echo "Not a repository or unstaged.";
        exit 1;
    fi
}

# Get current branch/tag/commit name.
# no parameters.
getcurrBranch()
{
    CURRENT_BRANCH=`git branch | \
    awk -F " " '$1=="*" && substr($2,0,1)!="(" {print $2} $1=="*" \
    && substr($2,0,1)=="(" {print substr($4,0,length($4)-1)}'`;
    if [ -z "$CURRENT_BRANCH" ]; then
        echo "Get current branch failed.";
        exit 1;
    fi
}
# Ask user to confirm.
# no parameters.
confirm()
{
    if [ "$FORCE" != "y" ]; then
        read -p "Confirm $1? y/n default(y) : ";
        ch="$REPLY"
        if [ "$ch" == "y" -o "$ch" == "" ]; then
            return 0;
        fi
    else
        return 0;
    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值