关键词对比两个分支 unmerged_commits
unmerged_commits.sh
#!/bin/bash
# 脚本输出的是:SOURCE_BRANCH 有但 TARGET_BRANCH 没有的提交(按 patch 内容判断)。
# 设置分支名
TARGET_BRANCH="prod"
SOURCE_BRANCH="dev-xxx"
OUTPUT_FILE="unmerged_commits.csv"
# 确保我们在 git 仓库里
if [ ! -d .git ]; then
echo "当前目录不是一个 git 仓库"
exit 1
fi
# 确保分支都存在
if ! git show-ref --verify --quiet refs/heads/$SOURCE_BRANCH; then
echo "源分支 $SOURCE_BRANCH 不存在"
exit 1
fi
if ! git show-ref --verify --quiet refs/heads/$TARGET_BRANCH; then
echo "目标分支 $TARGET_BRANCH 不存在"
exit 1
fi
# 输出表头
echo "Commit Hash,Author,Date,Message" > "$OUTPUT_FILE"
# 获取未被 cherry-pick 的提交
git cherry -v $TARGET_BRANCH $SOURCE_BRANCH | grep '^+' | awk '{print $2}' | while read commit_hash; do
# 获取提交信息
author=$(git show -s --format='%an' $commit_hash)
date=$(git show -s --format='%ad' --date=short $commit_hash)
message=$(git show -s --format='%s' $commit_hash)
# 写入 CSV
echo "\"$commit_hash\",\"$author\",\"$date\",\"$message\"" >> "$OUTPUT_FILE"
done
echo "未合并提交已保存到 $OUTPUT_FILE"
作者:张三 创建时间:2026-02-28 16:37
最后编辑:张三 更新时间:2026-02-28 16:40
最后编辑:张三 更新时间:2026-02-28 16:40