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

相关推荐
Molesidy21 分钟前
【Git】【TortoiseGit】TortoiseGit安装与基础使用
git
lichong9518 小时前
Git 检出到HEAD 再修改提交commit 会消失解决方案
java·前端·git·python·github·大前端·大前端++
222you9 小时前
Git仓库推送到GitHub
git·github
你的人类朋友12 小时前
hotfix分支的使用
git·gitlab·github
小蜜蜂爱编程13 小时前
gerrit的部署与配置关联到不同服务器上的git仓库
运维·服务器·git·gerrit
颇有几分姿色15 小时前
Git将本地项目推送到GitLab
git·gitlab
Kent_J_Truman19 小时前
Git个人配置偏好记录以及注意事项
git
小龙报21 小时前
《算法每日一题(1)--- 连续因子》
c语言·开发语言·c++·windows·git·算法·visual studio
To_再飞行1 天前
Linux Bash(一)
linux·运维·服务器·bash
今禾1 天前
Git完全指南(中篇):GitHub团队协作实战
前端·git·github