• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

chatGPT,半小时git自动拉取代码

武飞扬头像
蓑衣夜行
帮助2

利用chatGPT,半小时搞定git自动拉取代码

果然是工具利用的好,极大的提高了生产力啊。

对我shell这种都没有写过100行代码的人来说,真的是提高了工作效率。按照以往的经验,我一边谷歌,一边写代码,至少也要半天时间。

先来预览下结果:

学新通

上面的执行环境,就是我之前的文章写过的开源软件

脚本update_code.sh仓库在:https://github.com/MingYueRuYa/worktools https://gitee.com/liushixiong/worktools

脚本实现以下几个功能:

  • 自动fetch代码
  • 自动rebase
  • 自动stash和stash pop
  • 自动更新子模块
#!/bin/sh

RED='\e[1;31m' # 红
RES='\e[0m'

GREEN='\033[32m' # 绿色
GREEN_END='\033[0m'

function echo_red {
        echo -e "${RED}************$1************${RES}"
}

function echo_green {
        echo -e "${GREEN}************$1************${GREEN_END}"
}

stashed=0

# ./update.sh -h 显示用法
while getopts ":h" opt; do
  case $opt in
    h)
          echo "usage:./update_code.sh remote_svr branch_name"
      exit 0
      ;;
  esac
done

if [ $# -eq 0 ]; then
  echo_green "No parameters provided, use default parameters"
  remote_svr="origin"
  remote_branch="master"
else
        if [ $# -eq 1 ]; then
                remote_svr=$1
                remote_branch="master"
        elif [ $# -eq 2 ]; then
                remote_svr=$1
                remote_branch=$2
        fi
fi

echo_green "remote server:"$remote_svr
echo_green "remote branch name:"$remote_branch

echo ""

# 获取git remote出来的远程服务器名称,并将多个名称放入数组中
# remote_names=($(git remote))

# 输出数组中的所有元素
# for name in "${remote_names[@]}"
# do
#   echo "The remote server name is: $name"
# done

# 查看是否有文件,子模块修改
echo_red "git status start"
status=$(git status --porcelain -uno)

if [ -n "$status" ]; then
        echo_red "modified files"
        echo "$status"
        echo_red "modified files"

        echo ""

        echo_red "git stash start"
        git stash
        echo_red "git stash end"
        echo ""

        stashed=1

        # 如果有3rd,hc字段,表示有子模块更新
        # 第三方子仓库的目录组织方式,必须如下: .../3rd/  .../hc/
        if echo "$status" | grep -qE "idl|hc"; then
                echo_red "update submodule starts"
                git submodule update --init --recursive
                echo_red "update submodule end"
                git stash
        fi
else
        echo_green "Not find any modified."
fi
echo_red "git status end"

echo ""

# 远程服务器的名称,可能存在多个,
# 所以约定成俗,上游的服务器统称为up(upstream)
echo_red "git fetch $remote_svr start"
git fetch $remote_svr
echo_red "git fetch $remote_svr end"

echo ""

# 远程服务器的分支格式必须是统一的。
# 如:up/release/branch_name,从本地的分支获取名字,组成远程分支名称
echo_red "git rebase start"
# 这种方式要求本地分支和远程名称一致,且满足特定的格式。
# 条件苛刻,故不再采用,而是采用将分支名通过参数传递
# branch_name=$(git rev-parse --abbrev-ref HEAD)
# version=$(basename "$branch_name")
git rebase "$remote_svr/$remote_branch"
echo_red "git rebase end"

echo ""

if [ $stashed -eq 1 ]; then
        echo_red "git stash pop start"
        git stash pop
        echo_red "git stash pop end"
fi


发现chatGPT真的是很强大。

对于大型项目来说,有了自动拉取代码。每天自己定时拉个代码,自动编译。早上过来就直接开工,不用再等个十几分钟。还是极大的方便。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhiagacc
系列文章
更多 icon
同类精品
更多 icon
继续加载