Wednesday, September 24, 2014

git 打包的一个bash 函数


資料來源: http://blog.csdn.net/free2o/article/details/3981786




Here is my bash alias. The argument is the <branch name> to export.
An example:

    cd /path/to/foo/
    _gittar master

The output is (time in ISO 8601 / UTC):

    ../foot-YYYYMMDD.HHMM.tar.gz

function _gittar ()
{
    local name=$(pwd)
    name=${name##*/}

    if [ ! "$1" ]; then
        echo "[ERROR] what branch to export?"
        return 1
    fi

    local date=$(TZ=UTC date '+%Y%m%d.%H%M')
    local pkg="$name-$date"
    local dir=".."
    local tar="$dir/$pkg.tar.gz"

    git archive /
        --format=tar /
        --prefix="$pkg/" /
        "$@" |
    gzip --best > "$tar"

    echo $tar
}

No comments: