Compare commits

2 Commits

Author SHA1 Message Date
6d590673ae Merge branch 'feature/merge-cleanup-script'
All checks were successful
部署-局域网 / deploy (push) Successful in 4s
2026-11-10 12:36:10 +08:00
89c7782768 chore: 新增 feature 分支合并后自动清理脚本 2026-11-10 12:36:09 +08:00

29
tools/finish-feature.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# 在 feature 分支上执行:合并到 main、推送、删除本地和远端分支
# 用法:bash tools/finish-feature.sh
set -euo pipefail
BRANCH=$(git branch --show-current)
if [[ ! "$BRANCH" =~ ^feature/ ]]; then
echo "❌ 当前分支不是 feature/*:${BRANCH}"
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "❌ 工作区有未提交改动,先提交或暂存"
exit 1
fi
echo "== 合并 ${BRANCH} → main"
git checkout main
git pull --ff-only origin main
git merge --no-ff "$BRANCH" -m "Merge branch '${BRANCH}'"
git push origin main
echo "== 清理分支 ${BRANCH}"
git branch -d "$BRANCH"
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
git push origin --delete "$BRANCH"
fi
echo "✅ 已合并并清理 ${BRANCH}"