shell获取git最近一次提交信息_【git】之使用shell脚本提交代码

#!/bin/sh# @author Hubal

# @Email Hubal@123.com

# @createBy2018-11-30# Shell脚本提交git代码 简单,快速,高效

#

author=Hubalecho '>>>>>> start push <<<<<

echo "====== 当前分支 ======"branch=git branchecho$branch

# 判断参数1是否包含参数2

contains_str(){

#echo ">>> $1 <<

elsereturn0

fi}

git_add(){echo ">>>>>> 执行 git add 之前,本地文件状态如下 <<<<<

statusResult=$(git status)

no_change="nothing to commit"contains_str"$statusResult" "$no_change"

if [[ $? == 1 ]]; then

echo "=== 当前没有新增或者修改的文件 ==="git_push

exitfiread-p "是否确定add?Y|N :"add_paramsif [[ $add_params == "Y" || $add_params == "y" ]]; thengit add .elseexitfi}

git_commit(){echo ">>>>>> 执行 git commit 之前,本地文件状态如下 <<<<<

read-p "是否确定commit?Y|N :"commit_paramsif [[ $commit_params == "Y" || $commit_params == "y" ]] ; thenread-p "请输入commit信息:"commit_msgif [ -z $commit_msg ] ; thengit commit-m "git commit by $author".elsegit commit-m $commit_msg .fi

elif [[ $commit_params == "N" || $commit_params == "n" ]] ; thenexitelseexitfi}

git_push(){echo ">>>>>> 执行 git push 之前,本地文件状态如下 <<<<<

current_branch=$(git symbolic-ref --short -q HEAD)echo ">>>>>> 当前分支:$current_branch <<<<<

echo ">>>>>> end push <<<<<

push_result="";if [[ -z $origin_params && -z $branch_params ]]; then

echo ">>>>>> push origin $current_branch"

sleep 5git push origin $current_branchelif [[ -n $origin_params && -n $branch_params ]]; then

echo ">>>>>> push $origin_params $branch_params"

sleep 5git push $origin_params $branch_paramselif [[ -z $origin_params && -n $branch_params ]]; then

echo ">>>>>> push origin $branch_params"

sleep 5git push origin $branch_paramselif [[ -n $origin_params && -z $branch_params ]]; then

echo ">>>>>> push $origin_params $current_branch"

sleep 5git push $origin_params $current_branchelse

echo ">>>>>> end push <<<<<

fi}

read-p "默认push当前分支,Q代表quit,其他单词代表切换分支 :"branchif [[ $branch == "Y" || $branch == "y" || -z $branch ]] ; then#echo "你输入的是: $branch"statusResult=$(git status)

to_commit="Changes to be committed"contains_str"$statusResult" "$to_commit"

if [[ $? != 1 ]]; thengit_add;elsegit add .echo "====== 本地没有需要add的文件,直接commit ======"

figit_commit;

git_push;

exit;elif [[ $branch == "Q" || $branch == "q" ]] ; then#echo "你输入的是: $branch ,代表退出当前操作!"exitelsegit checkout $branchecho -e "当前分支: \n $(git branch)"git_add;

git_commit;

git_push;

exit;fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值