2015年04月14日 My scripts for git
_ My scripts for git
These are my scripts for git in only local using :P
git_setup.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_setup.$$.*.tmp } # function func_help { echo "Usage : $0 [-u USER_NAME] [-m MAIL_ADDRESS]" echo "configure setup." echo "show config without any options." echo "" echo " -u USER_NAME user name for git." echo " -m MAIL_ADDRESS e-mail address for git." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # username="" email="" while [ "$#" != "0" ] do case $1 in -u ) shift username=$1 ;; -m ) shift email=$1 ;; *) func_help exit 1 ;; esac shift done # if [ "X${username}" != "X" ] then git config --global user.name "${username}" fi # if [ "X${email}" != "X" ] then git config --global user.email ${email} fi # git config --get user.name git config --get user.email # func_sweep # exit 0
git_init.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_init.$$.*.tmp } # function func_help { echo "Usage : $0 [-b]" echo "initialize source directory." echo "" echo " -b initialize for bare repository." echo "" echo ".gitignore sample" echo " .gitignore" echo " .*" echo "" echo ".gitatributes sample" echo " .exe binary" echo " .xls binary" echo " .xlsx binary" echo " .doc binary" echo " .docx binary" } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # bare="" while [ "$#" != "0" ] do case $1 in -b) bare="--bare" ;; *) func_help exit 1 ;; esac shift done # git init ${bare} git config --local core.quotepath false # func_sweep # exit 0
git_commit.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_commit.$$.*.tmp } # function func_help { echo "Usage : $0 [-m MESSAGE]" echo "commit all updates." echo "" echo " -m MESSAGE message with commit(default YYYY/MM/DD hh:mm:ss)." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # message="" all="no" while [ "$#" != "0" ] do case $1 in -m ) shift message="$1" ;; -a ) all="yes" ;; *) func_help exit 1 ;; esac shift done # if [ "X${message}" = "X" ] then message=`date +"%Y/%m/%d %H:%M:%S"` fi # if [ "X${all}" = "Xyes" ] then for i in `find . -name .git` do dir=`echo $i | sed -e 's/\.git$//'` (cd ${dir} && git add *; git commit -a -m "${message}") done else git add * git commit -a -m "${message}" fi # func_sweep # exit 0
git_branch.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_branch.$$.*.tmp } # function func_help { echo "Usage : $0 [-a]" echo " $0 -c BRANCH [-p POINT]" echo " $0 -d BRANCH" echo " $0 -g BRANCH" echo " $0 -m BRANCH" echo "manage branch." echo "show branches without any options or with -a option." echo "" echo " -a show both branches in local and remote." echo " -c BRANCH create BRANCH." echo " -p POINT point which branch from(default HEAD)." echo " -d BRANCH delete BRANCH." echo " -g BRANCH go to BRANCH." echo " -m BRANCH merge BRANCH." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # all="" opt_branch="" branch="" point="" while [ "$#" != "0" ] do case $1 in -a) all="$1" ;; -c | -d | -g | -m) opt_branch="$1" shift branch="$1" ;; -p) shift point="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${opt_branch}" = "X-c" ] then git branch ${branch} ${point} elif [ "X${opt_branch}" = "X-d" ] then git branch -D ${branch} elif [ "X${opt_branch}" = "X-g" ] then git checkout ${branch} elif [ "X${opt_branch}" = "X-m" ] then git merge ${branch} else git branch ${all} fi # func_sweep # exit 0
git_status.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_status.$$.*.tmp } # function func_help { echo "Usage : $0" echo "show status." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # git status # func_sweep # exit 0
git_tag.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_tag.$$.*.tmp } # function func_help { echo "Usage : $0 -c TAG_NAME [-m MESSAGE]" echo " $0 -d TAG_NAME" echo "manage tag." echo "show tags without any options." echo "" echo " -c TAG_NAME create tag." echo " -m MESSAGE message with tag(default YYYY/MM/DD hh:mm:ss)." echo " -d TAG_NAME delete tag." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # action="" tag="" message="" while [ "$#" != "0" ] do case $1 in -c ) action=$1 shift tag="$1" ;; -m ) shift message="$1" ;; -d ) action=$1 shift tag="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${message}" = "X" ] then message=`date +"%Y/%m/%d %H:%M:%S"` fi # if [ "X${action}" = "X" ] then git tag elif [ "X${action}" = "X-c" ] then git tag -a -f "${tag}" -m "${message}" elif [ "X${action}" = "X-d" ] then git tag -d "${tag}" else func_help exit 1 fi # func_sweep # exit 0
git_log.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_log.$$.*.tmp } # function func_help { echo "Usage : $0 [-d]" echo "show log." echo "" echo " -d show log with diff." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # opt_diff="" while [ "$#" != "0" ] do case $1 in -d ) shift opt_diff="-p" ;; *) func_help exit 1 ;; esac shift done # git log ${opt_diff} # func_sweep # exit 0
git_diff.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_diff.$$.*.tmp } # function func_help { echo "Usage : $0" echo "show diff between comitted source and uncomitted source." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # git diff # func_sweep # exit 0
git_export.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_export.$$.*.tmp } # function func_help { echo "Usage : $0 -d DEST_DIR [-p POINT]" echo "export source into directory." echo "" echo " -d DEST_DIR directory which export sources into." echo " -p POINT point to export(default HEAD)." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # destdir="" point="" while [ "$#" != "0" ] do case $1 in -d ) shift destdir="$1" ;; -p ) shift point="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${destdir}" = "X" ] then func_help exit 1 fi # if [ "X${point}" = "X" ] then point="HEAD" fi # if [ ! -e "${destdir}" ] then mkdir "${destdir}" fi export destdir git archive --format=tar ${point} | (cd ${destdir} && tar xvf -) # func_sweep # exit 0
git_show.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_show.$$.*.tmp } # function func_help { echo "Usage : $0 -p POINT -f FILE" echo "show file at specified point." echo "" echo " -p POINT point to show(default HEAD)." echo " -f FILE file to show." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # point="" file="" while [ "$#" != "0" ] do case $1 in -p ) shift point="$1" ;; -f ) shift file="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${point}" = "X" ] then point="HEAD" fi # git show ${point}:${file} # func_sweep # exit 0
git_clone.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_clone.$$.*.tmp } # function func_help { echo "Usage : $0 -u URI [-d DIRECTORY]" echo "clone URI into DIRECTORY." echo "" echo " -u URI URI to get." echo " -d DIRECTORY DIRECTORY to get into." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # uri="" dir="" while [ "$#" != "0" ] do case $1 in -u ) shift uri="$1" ;; -d ) shift dir="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${dir}" = "X" ] then git clone "${uri}" else git clone "${uri}" "${dir}" fi # func_sweep # exit 0
git_pull.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_pull.$$.*.tmp } # function func_help { echo "Usage : $0 [-u URI]" echo "fetch and merge sources from URI." echo "" echo " -u URI URI to get(default URI which cloned from)." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # uri="" while [ "$#" != "0" ] do case $1 in -u ) shift uri="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${uri}" = "X" ] then git pull else git pull "${uri}" fi # func_sweep # exit 0
git_push.sh
#! /bin/sh trap "func_sweep; exit 1" INT TERM # function func_sweep { rm -f /tmp/git_push.$$.*.tmp } # function func_help { echo "Usage : $0 [-u URI] [-f LOCAL_BRANCH] [-t REMOTE_BRANCH]" echo "push sources into URI." echo "" echo " -u URI URI to get(default URI which cloned from)." echo " -f LOCAL_BRANCH local branch name to push from." echo " -t REMOTE_BRANCH remote branch name to push into." } # if [ "X$1" = "X-h" -o "X$1" = "X--help" ] then func_help exit 1 fi # uri="" local_branch="" remote_branch="" while [ "$#" != "0" ] do case $1 in -u ) shift uri="$1" ;; -f ) shift local_branch="$1" ;; -t ) shift remote_branch="$1" ;; *) func_help exit 1 ;; esac shift done # if [ "X${uri}" = "X" ] then if [ "X${local_branch}" = "X" -a "X${remote_branch}" = "X" ] then git push else git push "${local_branch}:${remote_branch}" fi else if [ "X${local_branch}" = "X" -a "X${remote_branch}" = "X" ] then git push "${uri}" else git push "${uri}" "${local_branch}:${remote_branch}" fi fi # func_sweep # exit 0
.gitignore
.gitignore .*
.gitatributes
.exe binary