git,bash - 例子整理

文章目录

git,bash - 例子整理

概述

在git bash中的脚本和linux bash中好像差不多。

整理一些例子,为以后做参考

笔记

遍历目录,找到目标文件后干活

bash 复制代码
#!/bin/bash
# git bash 脚本 - 遍历修改当前目录下得所有 .gitmodules , 替换https 库 url 到 ssh 库 url

# 前置操作 : 写好my_task.sh后,给执行权限
# chmod 777 ./my_task.sh

# 前置操作 : 检查脚本的语法是否正确?
# bash -n my_task.sh
# 如果没看到输出,就说明脚本语法是正确的

# 运行脚本
# 进入到脚本的目录
# ./my_task.sh

clear
echo "---------- my_task.sh running ----------"

# echo "current user:(" $(whoami) ")"

# log begin time
echo "begin : ($(date '+%Y-%m-%d %H:%M:%S'))"

# =号两边不能有空格
file_cnt=0

find . -type f -name ".gitmodules" -print0 | while IFS= read -r -d '' file; do
    dir=$(dirname "$file")
    (
        cd "$dir" || { echo "⚠️ dir switch err: $dir"; exit 1; }
        
        # echo "finding $(pwd)/.gitmodules"
        if [ -f "$(pwd)/.gitmodules" ]; then 
            echo "!!! ($((file_cnt + 1))) was found $(pwd)/.gitmodules, ready to process"
            sed -i 's|https://github.com/|[email protected]:|g' .gitmodules
            git submodule sync --recursive
        fi    
    )

    file_cnt=$((file_cnt + 1))
done

# log end time
echo "end   : ($(date '+%Y-%m-%d %H:%M:%S'))"

END

相关推荐
嵌入式up3 小时前
Git生成公钥及gitlab配置公钥
git·gitlab
IT小饕餮16 小时前
linux /bin/bash丢失修复
linux·运维·bash
陈龙龙的陈龙龙19 小时前
macOS 安装 Homebrew、nvm 及安装切换 node 版本
前端·macos·bash
lucky登21 小时前
Git学习
git·学习
胡耀超1 天前
Xinference大模型配置介绍并通过git-lfs、hf-mirror安装
人工智能·git·python·大模型·llm·xinference
tanyongxi661 天前
Linux 中 Git 使用指南:从零开始掌握版本控制
linux·git
大白的编程日记.1 天前
【Git学习笔记】Git结构原理及其分支管理模型分析
笔记·git·学习
马院代表人1 天前
Java入职篇(4)——git的使用
java·git·职场和发展
gs801401 天前
GitLab 配置 Git LFS(Large File Storage)指南
git
longerxin20201 天前
使用curl随机间隔访问URL-使用curl每秒访问一次URL-nginx
c语言·开发语言·bash