TGTGInsighttelegram intelligenceLIVE / telegram public index
← V2EX
V2EX avatar

TGINSIGHT POST

Post #201770

@pushv2ex

V2EX

Views7帖子阅读量
发布4月16日2026/04/16 16:19
Post content

帖子内容

[程序员] 让 ai 重写了整个 git 的历史,强迫症被拯救了 个人项目,不需要协作,所以才敢这么折腾。 今天翻 git log ,发现历史里一堆 "update"、"fix"、"改一下" 这种毫无信息量的 commit message ,看着就难受。于是让 AI 把所有这类"废话 message"挑出来,结合实际 diff 分析改动内容,重新生成了有意义的描述。担心它改错,顺手让它写了个批处理 bash 脚本: bash#!/usr/bin/env bash set -euo pipefail # 用法:./rewrite.sh [分支名] [--yes] [--dry-run] # 旧 commit hash -> 新 message declare -A MESSAGES=( ["69298b6141"]="chore(tasks): remove vendored tasks source" ["b3aaeff723"]="chore(claude): add local permissions config" ["032c032074"]="fix(testing): set mobile initial path" # ... 其他映射 ) # 解析参数 TARGET="${1:-$(git branch --show-current)}" AUTO_YES=0 DRY_RUN=0 [[ "$*" =~ --yes ]] && AUTO_YES=1 [[ "$*" =~ --dry-run ]] && DRY_RUN=1 # 预览变更 echo "目标分支: $TARGET" for commit in "${!MESSAGES[@]}"; do echo " $commit -> ${MESSAGES[$commit]}" done # dry-run 模式 if [ $DRY_RUN -eq 1 ]; then echo "干运行模式,不实际修改" exit 0 fi # 二次确认 if [ $AUTO_YES -eq 0 ]; then read -p "确认重写提交消息?[y/N] " -r [[ ! $REPLY =~ ^[Yy] ]] && exit 0 fi # 自动备份 BACKUP="backup-$(date +%Y%m%d-%H%M%S)" git branch "$BACKUP" "$TARGET" # 执行重写 git filter-branch -f --msg-filter ' case "$GIT_COMMIT" in '"$(for hash in "${!MESSAGES[@]}"; do echo "$hash) echo \"${MESSAGES[$hash]}\" ;;" done)"' *) cat ;; esac ' -- "$TARGET" echo "完成!备份分支: $BACKUP" echo "如需恢复: git reset --hard $BACKUP"跑完脚本,看着 git log 整整齐齐,莫名被治愈了。