Git 快速提交脚本
命令
gcp [commit] [origin] [tag]
配置
1、将脚本添加至工作目录
/Users/ovim/shell/quick-commit-push-tag.sh
# 当前目录
CURRENT_DIR=$(pwd)
# 切换目录
cd $CURRENT_DIR
# 快捷定义
# 备注内容
commit=''
if [ $1 ]; then
commit=$1
fi
# 远程
remote=''
if [ $2 ]; then
remote=$2
fi
# 标签
tag=''
if [ $3 ]; then
tag=$3
fi
# 确认此目录是否存在.git
if [ ! -d "./.git" ]; then
echo "当前目录未设置 git 环境,执行失败"
exit;
fi
# 填写 commit 信息
if [ ! $commit ]; then
read -p "请输入 commit 信息:" commit
if [ ! $commit ]; then
echo "commit 信息不能为空"
exit;
fi
fi
# 提交
git add ./ && git commit -m "$commit"
# 填写 远程仓库名称
if [ ! $remote ]; then
read -p "请输入远程仓库名称,不输入默认为 origin:" remote
if [ ! $remote ]; then
remote='origin'
fi
fi
# 拉取并推送
git pull $remote master && git push -u $remote master
if [ $? -ne 0 ]; then
echo "拉取并推送执行失败:请处理"
exit;
fi
# # tag 标签处理
if [ $tag ]; then
# 清除已存在的标签
git tag -d $tag && git push $remote :refs/tags/$tag
# 创建新标签
git tag $tag && git push $remote $tag
fi
2、设置可执行权限
chmod +x /Users/ovim/shell/quick-commit-push-tag.sh
3、设置快速命令
vim ~/.zshrc
# 添加如下内容
alias gcp="sh /Users/ovim/shell/quick-commit-push-tag.sh"
3、测试
需在有git环境的文件目录下执行
cd ~/Desktop/testGit
gcp update origin v0.1