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/|git@github.com:|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

相关推荐
活宝小娜1 小时前
git windows安装教程
git
青春喂了后端3 小时前
Go Sidecar Repository 并发锁改造:让并发请求安全地进入 Git 仓库层
git·安全·golang
小雨青年3 小时前
GitHub Actions 工作流性能优化实战,先看瓶颈,再改缓存和并发
git
0x00074 小时前
Git Bash 中无法启动 Claude Code ?
开发语言·git·bash
xuhaoyu_cpp_java5 小时前
Git学习(六)
git·学习
IMPYLH5 小时前
Linux 的 users 命令
linux·运维·服务器·前端·数据库·bash
happyness4421 小时前
Git:AI编程时代的“安全带“与“时光机“
git·ai编程
To_OC1 天前
踩坑无数!终于捋顺Git基础核心工作流(新手必看)
git·程序员
IMPYLH1 天前
Linux 的 whoami 命令
linux·运维·服务器·bash
xuhaoyu_cpp_java1 天前
Git学习(三)
经验分享·笔记·git·学习