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

相关推荐
IMPYLH10 分钟前
Linux 的 logname 命令
linux·运维·服务器·bash
IMPYLH27 分钟前
Linux 的 ln 命令
linux·运维·服务器·bash
小比特_蓝光1 小时前
版本控制器Git/调试器gdb/cgdb使用
git
海参崴-2 小时前
Git使用完全指南
git
Jp7gnUWcI2 小时前
AI Compose Commit:用 AI 智能重构 Git 提交工作流
人工智能·git·重构
小柯博客2 小时前
从零开始打造 OpenSTLinux 6.6 Yocto 系统 - STM32MP2(基于STM32CubeMX)(八)
c语言·git·stm32·单片机·嵌入式硬件·嵌入式·yocto
eastyuxiao11 小时前
如何在不同的机器上运行多个OpenClaw实例?
人工智能·git·架构·github·php
Islucas13 小时前
Claude code入门保姆级教程
python·bash·claude
bu_shuo13 小时前
git练习学习网站【中文网站】
git·学习
秃秃然然14 小时前
Git指北
git