Files
qwsy/材料/code/统计git提交-gitbsah使用.sh
binghuai 1b133175a2 11.26
2025-11-27 11:02:31 +08:00

36 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 脚本名称: git_history_exporter.sh
# 功能: 提取所有分支的提交记录,按时间排序,并输出到文件。
# 输出文件名
OUTPUT_FILE="git_commit_history_with_branches.txt"
echo "======================================================="
echo " 💻 Git 提交历史导出脚本 (含分支信息) 📜"
echo "======================================================="
# **新格式定义:**
# %ad: 日期 | %h: 哈希 | %d: **引用/分支名称** | %an: 作者 | %s: 主题 | %n%b: 换行和正文
COMMIT_FORMAT="%ad | %h %d | %an | %s%n%b"
echo "正在从所有分支提取提交记录,并按时间排序..."
# 运行 git log并将结果直接写入文件
# --all 确保查看所有分支
# --decorate=short 确保 %d 输出的引用信息简短
# --reverse 按时间从早到晚排序
git log --all --reverse --decorate=short \
--date=format:'%Y-%m-%d %H:%M:%S' \
--pretty=format:"$COMMIT_FORMAT" \
> "$OUTPUT_FILE"
# 在 MINGW64 环境下,添加换行符兼容性修复
echo "正在确保文件换行符兼容 Windows (CRLF)..."
# 使用 sed 确保文本文件在 Windows 记事本中正常显示
sed -i 's/\r$//' "$OUTPUT_FILE"
sed -i 's/$/\r/' "$OUTPUT_FILE"
echo "✅ 提交记录已成功导出到文件:"
echo " $OUTPUT_FILE"
echo "======================================================="