【git】之使用shell脚本提交代码
生活随笔
收集整理的這篇文章主要介紹了
【git】之使用shell脚本提交代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為減少提交步驟,防止提交錯誤,使用Shell腳本進行git提交不失一件好事
#!/bin/sh # @author Hubal # @Email Hubal@123.com # @createBy 2018-11-30 # Shell腳本提交git代碼 簡單,快速,高效 # author = Hubal echo ' >>>>>> start push <<<<<< ' echo " ====== 當前分支 ====== " branch= git branch echo $branch # 判斷參數1是否包含參數2 contains_str(){# echo " >>> $1 <<< "# echo " <<< $2"contains_result=$(echo $1 | grep "${2}")if [[ -n $contains_result ]] ; thenreturn 1elsereturn 0 fi}git_add(){echo ">>>>>> 執行 git add 之前,本地文件狀態如下 <<<<<<"git status statusResult=$(git status)no_change="nothing to commit"contains_str "$statusResult" "$no_change"if [[ $? == 1 ]]; thenecho "=== 當前沒有新增或者修改的文件 ==="git_pushexitfiread -p "是否確定add?Y|N : " add_paramsif [[ $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_paramsif [[ $commit_params == "Y" || $commit_params == "y" ]] ; thenread -p "請輸入commit信息: " commit_msgif [ -z $commit_msg ] ; then git commit -m "git commit by $author" .elsegit commit -m $commit_msg . fielif [[ $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_confirmif [[ $push_confirm != "Y" && $push_confirm != "y" ]]; thenecho ">>>>>> end push <<<<<<"exitfiread -p "請輸入遠程git地址別名,默認是origin: " origin_params echo -e "\n"read -p "請輸入遠程分支名稱,默認是當前分支: " branch_paramspush_result="";if [[ -z $origin_params && -z $branch_params ]]; thenecho ">>>>>> push origin $current_branch"sleep 5 git push origin $current_branch elif [[ -n $origin_params && -n $branch_params ]]; thenecho ">>>>>> push $origin_params $branch_params"sleep 5 git push $origin_params $branch_paramselif [[ -z $origin_params && -n $branch_params ]]; thenecho ">>>>>> push origin $branch_params"sleep 5 git push origin $branch_paramselif [[ -n $origin_params && -z $branch_params ]]; thenecho ">>>>>> push $origin_params $current_branch"sleep 5 git push $origin_params $current_branch elseecho ">>>>>> 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 [[ $? != 1 ]]; thengit_add;else git add . echo " ====== 本地沒有需要add的文件,直接commit ====== "figit_commit;git_push;exit;elif [[ $branch == "Q" || $branch == "q" ]] ; then# echo "你輸入的是: $branch ,代表退出當前操作!" exit else git checkout $branchecho -e "當前分支: \n $(git branch) " git_add;git_commit;git_push;exit; fi?
轉載于:https://www.cnblogs.com/gyjx2016/p/10058209.html
總結
以上是生活随笔為你收集整理的【git】之使用shell脚本提交代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery可放大预览的图片滑块
- 下一篇: Scala 读取文件