使用GIT子命令 规范自己的commit

  • A+
所属分类:git

复制下列代码新建shell文件(不用加后缀.sh)

#!/bin/sh
RED="\033[1;31m"
GREEN="\033[1;32m"
NOCOLOR="\033[0m"

die() {
	echo "$*" 1>&2 ; 
	exit 1; 
}

git_current_name() {
	local branch_name

	branch_name="$(git config --get user.name)"
	[ -z $branch_name ] && die "get GIT name failed"
	echo "$branch_name"
}

echo -e "${GREEN}pelase select commit type: ${NOCOLOR}"

declare -a arr=("feat" "bugfix" "release" "style" "refactor")

len=${#arr[@]}

select choice in "${arr[@]}";do
    case $choice in
        "feat")
			break
            ;;
        "bugfix")
			break
            ;;
        "release")
			break
            ;;
        "style")
			break
            ;;
        "refactor")
            break
            ;;
        *)
            echo "enter error"
            exit 2
            ;;
    esac
done

read -p "请输入提交描述: " DESC

date=`date +%Y%m%d%H%M%S`
user=$(git_current_name)

echo -e "[${RED}$choice${NOCOLOR}] ${GREEN}(${date}_${user}_${choice}_${DESC})${NOCOLOR}"

echo `git add .`
echo `git commit -m ${date}_${user}_${choice}_${DESC}`

将文件移动到 ~/usr/bin目录下

mv [目标文件] ~/usr/bin
weinxin
我的微信
欢迎来撩!!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: