*完全由本人原创,转载请注明出处哦~
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;