linux中使用git获取所有分支,并获取所有分支中的logs然后输出保存为diff文件

c 复制代码
#!/bin/bash

# 创建目录用于存储每个分支的文件
mkdir branches

# 获取所有分支
branches=$(git branch -a)

# 遍历所有分支
for branch in $branches; do
  # 在每个分支上切换
  git checkout $branch
  
  # 使用git log --oneline将日志附加到all.log文件
  git log --oneline > all.log

  # 获取分支名
  branch_name=$(echo $branch | awk -F'/' '{print $NF}')

  # 创建分支文件夹
  mkdir "branches/$branch_name"

  # 遍历all.log文件的所有日志
  while read -r line; do
    # 解析每一行的id和name
    id=$(echo $line | awk '{print $1}')
    name=$(echo $line | awk '{print $2}')

    # 在分支文件夹下创建以name为文件名的.diff文件
    touch "branches/$branch_name/$name.diff"

    # 在.diff文件中写入相应的内容,这里只是一个示例
    echo "Changes for $name (ID: $id)" >> "branches/$branch_name/$name.diff"
    git diff $id >> "branches/$branch_name/$name.diff"
  done < all.log
done
相关推荐
Web极客码13 小时前
如何通过命令行工具检查 Linux 版本信息
linux·运维·服务器
Lynnxiaowen14 小时前
今天我们继续学习Kubernetes内容pod资源对象
运维·学习·容器·kubernetes·云计算
欢鸽儿14 小时前
Vitis】Linux 下彻底清除启动界面 Recent Workspaces 历史路径
linux·嵌入式硬件·fpga
繁华似锦respect14 小时前
C++ 智能指针底层实现深度解析
linux·开发语言·c++·设计模式·代理模式
远程软件小帮手14 小时前
云电脑挂机功能上线!边上班摸鱼边游戏多开教程
运维·服务器
hweiyu0015 小时前
Linux 命令:dd
linux
---学无止境---15 小时前
i386 架构中断管理函数详解
linux·架构
cike_y15 小时前
浅谈用docker搭建一个ctf镜像
运维·安全·网络安全·docker·容器·ctf
云和数据.ChenGuang15 小时前
运维工程师技术之openEuler 网卡基础查询指令
运维·中间件·mycat·运维工程师·运维技术
kkkkkkkkl2416 小时前
Prometheus指标入门详解
linux·服务器