打zZ~瞌睡 Menu

SVN导出两个版本之前添加或修改过的文件

在工作中,由于某种原因,部署于正式版本的代码不是由SVN直接更新的,这样在经过几次修改提交之后再发布修改的内容时会有点麻烦,需要对每个版本修改过的文件逐个检查上传。下面这个脚本文件可以导出两个版本之间添加过修改过的文件,导出后一起上传就可以了。

在工作中,由于某种原因,部署于正式版本的代码不是由SVN直接更新的,这样在经过几次修改提交之后再发布修改的内容时会有点麻烦,需要对每个版本修改过的文件逐个检查上传。下面这个脚本文件可以导出两个版本之间添加过修改过的文件,导出后一起上传就可以了。

#!/bin/bash

if [ ! $1 ] || [ ! $2 ] || [ ! $3 ] || [ ! $4 ]; then
    echo "Please enter a revision from, revision to, SVN repository, and target directory"
    exit
fi

# set up nice names for the incoming parameters to make the script more readable
revision_from=$1
revision_to=$2
repository=$3
target_directory=$4

# the grep is needed so we only get added/modified files and not the deleted ones or anything else
# if it's a modified directory it's " M" so won't show with this command (good)
# if it's an added directory it's still "A" so will show with this command (not so good)

for line in `svn diff --summarize -r$revision_from:$revision_to $repository | grep "^[AM]"`
do
    # each line in the above command in the for loop is split into two:
    # 1) the status line (containing A, M, AM, D etc)
    # 2) the full repository and filename string
    # so only export the file when it's not the status line
    if [ $line != "A" ] && [ $line != "AM" ] && [ $line != "M" ]; then
        # use sed to remove the repository from the full repo and filename
        filename=`echo "$line" |sed "s|$repository||g"`
        # don't export if it's a directory we've already created
        if [ ! -d $target_directory$filename ]; then
            directory=`dirname $filename`
            mkdir -p $target_directory$directory
            svn export -r $revision_to $line $target_directory$filename
        fi
    fi
done

# to summarize any deleted files or directories at the end of the script uncomment the following line
#svn diff --summarize -r$revision_from:$revision_to $repository | grep "^[D]"

将文件保存为svndiff,并将权限改为0755,使用方法:

# $from_version: 起始版本号
# $to_version  : 结束版本号
# $svn_repository: svn版本库地址,也可以是本地svn路径
# $target:         导出目录
svndiff $from_version $to_version $svn_repository $target