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

相关推荐
马院代表人1 小时前
Java入职篇(4)——git的使用
java·git·职场和发展
gs801402 小时前
GitLab 配置 Git LFS(Large File Storage)指南
git
longerxin20207 小时前
使用curl随机间隔访问URL-使用curl每秒访问一次URL-nginx
c语言·开发语言·bash
小薛博客16 小时前
Git常用操作之GitLab
java·git·gitlab·github·idea
郭顺发_18 小时前
使用GitHub Actions实现Git推送自动部署到服务器
服务器·git·github
中工钱袋19 小时前
Git 克隆问题排查与解决方案
git
龙智DevSecOps解决方案19 小时前
版本控制案例 | 硬盘巨头希捷(Seagate)的版本管理升级之路:从SVN到Perforce Helix Core
git·svn·版本控制·perforce·helix core
咩咩大主教1 天前
Gitlab报错:sudo: a password is required
linux·服务器·git·ubuntu·gitlab·shell·gitlabci/cd
tan180°2 天前
版本控制器Git(4)
linux·c++·git·后端·vim
晓纪同学2 天前
git使用命令总结
git·gitee·github·gitcode