使用git做代码提交每次都要不厌其烦的三步走:
git add include/mysql.php git commit -m "增加XXX接口文件,实现XXX功能" git push
时间长了,发现大部分时间都浪费在敲这几个命令上了,今天自己写了一个方法,直接一条命令实现上述三步的功能。具体实现如下:
vim ~/.bashrc
在该文件中增加如下函数:
function g() {
    log=$1 files=$2
    if [ ! -n "$log" ]; then 
        echo "必须输入提交说明"
        return 
    fi
    if [ ! -n "$files" ]; then
        files="."
    fi
    #git pull 
    git fetch
    git merge --no-edit
    git add $files
    git commit -m "$1"
    git push
}
添加并保存完毕。
source ~/.bashrc 或执行一下 bash 命令。
然后就可以通过如下命令直接做提交了。
(1)仅提交include/mysql.php文件
g "增加XXX接口文件,实现XXX功能" include/mysql.php
(2)提交当前目录即子目录的所有文件
g "增加XXX接口文件,实现XXX功能"