美文网首页
git提交远程仓库脚本

git提交远程仓库脚本

作者: Vayne_God | 来源:发表于2018-04-11 17:15 被阅读0次

在开发过程中,我们在提交代码到远程仓库时,需要进行一系列git add, git commit,git pull, git push等命令,而且在git add部分修改文件时,更加麻烦。因此,将一系列命令用脚本来执行,会事半功倍。该脚本可以指定提交部分file或者是全部提交,并可以指定commit message(mac上测试已经通过)

1、使用方式:./submit.sh 1 2 4 5 "commit message"

其中,1 2 4 5 为git status需要add的file的行号,最后一个参数为commit message。

如:git status后显示:

    modified:  src/test/java/com/zsq/xxx/xxx/service/IEvaOperaServiceTest.java

    modified:  src/test/java/com/zsq/xxx/xxx/service/IMapServiceTest.java

                                                ……

可以选择任意的行号进行add 和 commit。

如果选择全部,则可以使用 ./submit.sh . "commit message"

注意:

(1)如果脚本放在项目目录,则:

./submit.sh . "all commit"

(2)如果脚本放在项目目录的父目录,则命令为:

cd .. && ./submit.sh . "all commit" && cd 项目dir

2、脚本命名为submit.sh 内容如下:

#!/bin/bash 

#print the directory and file

# created by zsq on 2018/04/10

# modified these commands when project changes

# 进入项目目录
cd 项目dir
# 切换分支
git checkout dev-pinyin
# 拉取最新代码
git pull origin xxx

echo ${PWD}
# commit all files

if [[ "$1" == "." ]]; then

# add all files

git add .

git commit -m "$2"

echo "commit message: $2"

else

# choose files to add .

# please pay attention to the $# value when do shift operation,

# so a variable 'len' is nessisary to save the length of parameters in bash command tempororyly

echo "these files have been added to local git respository: "

len=$#

for ((i=0;i<$[${len}-1];i++));

do

# echo ${len}

a=$1

shift

var=$(git status | grep -E "new file|modified" | cut -d ' ' -f 4 | sed -n ${a}p)

echo "    ${a}--${var}"

git add  ${var}

done

# add commit message.

# in fact, there is only one parameter left which is the commit message

for (( i = $#; i < $[$#+1]; i++ )); do

a=$1

shift

# echo ${a}

echo "commit message: ${a}"

git commit -m "${a}"

done

fi

# push the commit to remote respository

git push

Tips: 黑体部分需要根据实际项目以及branch进行相应的变化

相关文章

  • Git常用命令笔记

    git命令使用 1 创建远程仓库(初始化--提交到本地仓库--提交到远程仓库) $ git init ...

  • git提交远程仓库脚本

    在开发过程中,我们在提交代码到远程仓库时,需要进行一系列git add, git commit,git pull,...

  • 通过Git将本地项目和远程仓库做关联

    添加远程代码仓库: git remote add origin 远程仓库地址 提交代码到远程仓库: git pus...

  • git 命令行操作笔记

    git中的选项解释 创建本地git仓库 提交代码到git仓库 本地git仓库添加到远程仓库中 克隆远程仓库到本地 ...

  • git从入门到精通

    查看git命令 初始化git仓库 克隆远程仓库(github) 添加新增的文件 提交到本地库 提交到远程maste...

  • git 工具

    初始化git仓库 添加文件 查看状态 提交文件 提交文件到远程仓库 更新远程仓库代码 查看分支 创建分支 提交分支...

  • Git命令

    git push 作用:将本地仓库中代码提交到远程仓库 语法 :git push 仓库地址 master git ...

  • Git基本操作和错误

    创建SSH Key 本地创建仓库操作 创建本地仓库 将文件添加进Git 提交 Git远程仓库操作 查看远程仓库 添...

  • git常用命令

    从远程仓库克隆,并在本地修改后,提交到远程仓库 git clone 远程仓库地址 将远程仓库克隆到本...

  • Android Studio项目上传至Git

    一、Git上传流程 Push:提交代码至仓库中(远程/本地)Commit:提交代码至本地仓库;Pull:远程仓库代...

网友评论

      本文标题:git提交远程仓库脚本

      本文链接:https://www.haomeiwen.com/subject/osszhftx.html