为减少提交步骤,防止提交错误,使用Shell脚本进行git提交不失一件好事

#!/bin/sh
# @author Hubal
# @Email Hubal@123.com
# @createBy --
# Shell脚本提交git代码 简单,快速,高效
#
author = Hubal
echo ' >>>>>> start push <<<<<< '
echo " ====== 当前分支 ====== "
branch= git branch
echo $branch # 判断参数1是否包含参数2
contains_str(){
# echo " >>> $1 <<< "
# echo " <<< $2" contains_result=$(echo $ | grep "${2}")
if [[ -n $contains_result ]] ; then
return
else
return
fi } git_add(){
echo ">>>>>> 执行 git add 之前,本地文件状态如下 <<<<<<"
git status
statusResult=$(git status)
no_change="nothing to commit" contains_str "$statusResult" "$no_change" if [[ $? == ]]; then
echo "=== 当前没有新增或者修改的文件 ==="
git_push
exit
fi read -p "是否确定add?Y|N : " add_params
if [[ $add_params == "Y" || $add_params == "y" ]]; then
git add .
else
exit
fi
} git_commit(){
echo ">>>>>> 执行 git commit 之前,本地文件状态如下 <<<<<<"
git status
read -p "是否确定commit?Y|N : " commit_params
if [[ $commit_params == "Y" || $commit_params == "y" ]] ; then
read -p "请输入commit信息: " commit_msg
if [ -z $commit_msg ] ; then
git commit -m "git commit by $author" .
else
git commit -m $commit_msg .
fi
elif [[ $commit_params == "N" || $commit_params == "n" ]] ; then
exit
else
exit
fi
} git_push(){
echo ">>>>>> 执行 git push 之前,本地文件状态如下 <<<<<<"
git status
current_branch=$(git symbolic-ref --short -q HEAD)
echo ">>>>>> 当前分支:$current_branch <<<<<<"
read -p "是否确定push?Y|N : " push_confirm
if [[ $push_confirm != "Y" && $push_confirm != "y" ]]; then
echo ">>>>>> end push <<<<<<"
exit
fi
read -p "请输入远程git地址别名,默认是origin: " origin_params
echo -e "\n"
read -p "请输入远程分支名称,默认是当前分支: " branch_params
push_result="";
if [[ -z $origin_params && -z $branch_params ]]; then
echo ">>>>>> push origin $current_branch"
sleep
git push origin $current_branch elif [[ -n $origin_params && -n $branch_params ]]; then
echo ">>>>>> push $origin_params $branch_params"
sleep
git push $origin_params $branch_params elif [[ -z $origin_params && -n $branch_params ]]; then
echo ">>>>>> push origin $branch_params"
sleep
git push origin $branch_params elif [[ -n $origin_params && -z $branch_params ]]; then
echo ">>>>>> push $origin_params $current_branch"
sleep
git push $origin_params $current_branch
else
echo ">>>>>> end push <<<<<<"
fi } read -p "默认push当前分支,Q代表quit,其他单词代表切换分支 : " branch
if [[ $branch == "Y" || $branch == "y" || -z $branch ]] ; then
# echo "你输入的是: $branch "
statusResult=$(git status)
to_commit="Changes to be committed"
contains_str "$statusResult" "$to_commit"
if [[ $? != ]]; then
git_add;
else
git add .
echo " ====== 本地没有需要add的文件,直接commit ====== "
fi
git_commit;
git_push;
exit; elif [[ $branch == "Q" || $branch == "q" ]] ; then
# echo "你输入的是: $branch ,代表退出当前操作!"
exit
else
git checkout $branch
echo -e "当前分支: \n $(git branch) "
git_add;
git_commit;
git_push;
exit;
fi

【git】之使用shell脚本提交代码的更多相关文章

  1. 通过shell脚本实现代码自动化部署

    通过shell脚本实现代码自动化部署 一.传统部署方式及优缺点 1.传统部署方式 (1)纯手工scp (2)纯手工登录git pull.svn update (3)纯手工xftp往上拉 (4)开发给打 ...

  2. Myeclipse如何使用自带git工具向远程仓库提交代码(转)

    Myeclipse如何使用自带git工具向远程仓库提交代码 第一步:将改动的代码标记 项目右键:team->synchronize workspace 点击确定 项目右键>add to g ...

  3. Apache下通过shell脚本提交网站404死链

    网站运营人员对于死链这个概念一定不陌生,网站的一些数据删除或页面改版等都容易制造死链,影响用户体验不说,过多的死链还会影响到网站的整体权重或排名. 百度站长平台提供的死链提交工具,可将网站存在的死链( ...

  4. shell重温---基础篇(shell变量&字符串以及git GUI运行shell脚本方式)

    既然是基础篇那肯定是需要对shell的各种需要注意的基本点进行说明了.接下来就是show time...    shell呢,是一个用C语言编写的应用程序,是用户使用linux的桥梁.所以呢,他既是一 ...

  5. 采用shell脚本统计代码的行数

    刚毕业那会儿有一次去台湾公司面试,我问多行代码怎么写.我从来没有想过这个问题,粗略计算,.惊叹:大概几十万行不行. 最近整理资料,看着eclipse左边全面上市,我觉得这个东西.代码共同拥有的行倒底总 ...

  6. mac链接linux终端,shell脚本发布代码

    项目的业务需求:从mac端直接连上linux服务终端,并发布相关的代码 一.使用ssh链接上linux服务端 1.cd ~/.ssh 2.vi config,按照下面的内容配置config文件,然后: ...

  7. git创建仓库,并提交代码(第一次创建并提交)(转)

    一直想学GIT,一直不曾学会.主要是GUI界面的很少,命令行大多记不住.今天尝试提交代码,按GIT上给的方法,没料到既然提交成功了. 于是把它记下来,方便以后学习. 代码是学习用的,没多大意义: 下图 ...

  8. Git创建远程分支并提交代码到远程分支

    1.可以在VS中新建分支 2.可以通过git branch -r 命令查看远端库的分支情况 这些红色都是远程的分支 3.从已有的分支创建新的分支(如从master分支),创建一个dev分支 (不用vs ...

  9. Myeclipse如何使用自带git工具向远程仓库提交代码

    先看一下Myeclipse自带的git工具  本人是在码云上面注册的账号,上面有项目的仓库,将仓库的项目克隆到本地之后,在myeclipse中导入该项目. 那么如何将修改后的代码再提交到码云上面? 第 ...

随机推荐

  1. windows平台python svn模块的一个小 bug

    环境 编程语言版本:python 2.7 操作系统:win10 64位 模块名:svn svn  checkout时报错 File "D:\Python27\lib\site-package ...

  2. flock

    为了确保操作的有效性和完整性,可以通过锁机制将并发状态转换成串行状态.作为锁机制中的一种,PHP的文件锁也是为了应对资源竞争.假设一个应用场景,在存在较大并发的情况下,通过fwrite向文件尾部多次有 ...

  3. Holer实现外网访问本地MySQL数据库

    外网访问内网MySQL数据库 内网主机上安装了MySQL数据库,只能在局域网内访问,怎样从公网也能访问本地MySQL数据库? 本文将介绍使用holer实现的具体步骤. 1. 准备工作 1.1 安装并启 ...

  4. 读取Excel,单元格内容大于255个字符自动被截取的问题

    DataSet ds = new DataSet(); cl_initPage.v_DeBugLog("ExcelDataSource进入"); string strConn; s ...

  5. win10操作系统 安装nodejs报2503错误解决方法

    报该错误的原因是由于安装操作没有获得足够的管理权限导致. 在电脑左下角开始菜单[右键]选择"命令提示符(管理员)“ 敲入如下命令 msiexec /package 后面加你nodejs的本机 ...

  6. 番外篇1:在Windows环境中安装JDK

    他山之石,可以攻玉!欢迎关注我的微信公众号 本文作为构建第一个Java程序的番外篇一,跟大家探讨下在Windows下怎么安装JDK.由于本人没有Mac,因此如果是Mac的同学,请自行百度哦! 读前预览 ...

  7. [LeetCode&Python] Problem 53. Maximum Subarray

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  8. firefox浏览器,主动出现hao123的解决办法

    听说火狐浏览器前端开发很好用,今天下载了一个体验了一下觉得还是很不错的.但是有个问题!!!为什么我设置了启动时打开空白页没用,它每次都会给我打开 https://www.hao123.com/ hao ...

  9. 练习题:试使用C#编程实现银行、ATM等功能

    练习题:试使用编程实现银行.ATM等功能 using System; using System.Collections.Generic; using System.Linq; using System ...

  10. 播放器: AVPlayer

    AVPlayer *player = [AVPlayer playerWithURL:[NSURL URLWithString:@"http://flv2.bn.netease.com/vi ...