git自动提交脚本

git自动提交脚本

每次在linux都要重新一遍一遍敲着这些重复的代码,我想着能够优化一下,做个一键脚本,减少重复劳动。

#!/bin/bash
git status
 
read -r -p "是否继续提交? [Y/n] " input
 
case $input in
    [yY][eE][sS]|[yY])
        echo "继续提交"
        git add -A
        git commit -m $1
        git push origin $2
                    exit 1
        ;;

    [nN][oO]|[nN])
        echo "中断提交"
        exit 1
            ;;

    *)
    echo "输入错误,请重新输入"
    ;;
esac
        

实际操作的时候命令行输入:./gitcommit.sh  commitMesage  branchName就可以了

循环提交脚本

#!/bin/bash
git status
 
while true;
do
    read -r -p "是否继续提交? [Y/n] " input
 
    case $input in
        [yY][eE][sS]|[yY])
            echo "继续提交"
            git add -A
            git commit -m $1
            git push origin $2
                        exit 1
            ;;
 
        [nN][oO]|[nN])
            echo "中断提交"
            exit 1
                   ;;
 
        *)
        echo "输入错误,请重新输入"
        ;;
    esac
done

操作跟单次提交一样

有时候,我们本地开发提交代码用svn,提交到代码仓库,然后代码仓库推送到目标服务器

#!/bin/bash
cd 代码路径
svn up
version=`svnversion |sed 's/^.*://' |sed 's/[A-Z]*$//'`
#version=`svn info|grep "Last Changed Rev"`
branch=仓库地址

git status
 
read -r -p "是否继续提交? [Y/n] " input
 
case $input in
    [yY][eE][sS]|[yY])
        echo "继续提交"
        git add .
        git commit -m $version
        git push $branch master
        ;;
 
    [nN][oO]|[nN])
        echo "中断提交"
        exit 1
               ;;
 
    *)
    echo "输入错误"
    exit 1
    ;;
esac

执行的时候直接./gitbash.sh 就好了,因为提交信息跟仓库地址我是直接写死的