zoukankan      html  css  js  c++  java
  • 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  commitMessage  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 就好了,因为提交信息跟仓库地址我是直接写死的,

    顺便总结一下git add的几个区别

    git add -A   保存所有的修改
    git add .    保存新的添加和修改,但是不包括删除
    git add -u   保存修改和删除,但是不包括新建文件

    svn的查询某一版本号的修改内容

    查看history

    svn log -l count /file/path #查看某一文件的最近count次提交信息

    比较不同版本

    svn diff -r PREV:COMMITTED /file/path    #查看最近一次提交的改动
    svn diff -r version1:version2 /file/path  #查看指定版本间的不同

    svn info跟svnversion这两个命令的区别

    svn info|grep "Last Changed Rev"          #得到当前路径文件提交的最后一次版本号
    svnversion |sed 's/^.*://' |sed 's/[A-Z]*$//'  #得到当前仓库地址的最新版本号
  • 相关阅读:
    【leetcode】1020. Partition Array Into Three Parts With Equal Sum
    【leetcode】572. Subtree of Another Tree
    【leetcode】123. Best Time to Buy and Sell Stock III
    【leetcode】309. Best Time to Buy and Sell Stock with Cooldown
    【leetcode】714. Best Time to Buy and Sell Stock with Transaction Fee
    【leetcode】467. Unique Substrings in Wraparound String
    【leetcode】823. Binary Trees With Factors
    【leetcode】143. Reorder List
    【leetcode】1014. Capacity To Ship Packages Within D Days
    【leetcode】1013. Pairs of Songs With Total Durations Divisible by 60
  • 原文地址:https://www.cnblogs.com/reasonzzy/p/11653895.html
Copyright © 2011-2022 走看看