npx claudepluginhub zwmmm/oh-my-claudecode --plugin ohhaikugit/# Git Rollback 详细指南 交互式回滚 Git 分支到历史版本,支持 reset 和 revert 两种模式。 > 💡 **建议**: 执行本命令前,建议先运行 `/clear` > 命令清理上下文,以获得更好的分析效果。 ## 目录 - [选项说明](#选项说明) - [交互流程](#交互流程) - [reset vs revert](#reset-vs-revert) - [安全护栏](#安全护栏) - [适用场景](#适用场景) --- ## 选项说明 | 选项 | 说明 | | ---------------------- | --------------------------------------------------------- | | `--branch <branch>` | 要回滚的分支;缺省时交互选择 | | `--target <rev>` | 目标版本(commit Hash、Tag、reflog 引用);缺省时交互选择 | | `--mode reset\|revert` | `reset`:硬回滚历...
/undoSafely reverts GSD phase or plan commits using the phase manifest with dependency checks and confirmation prompt. Supports --last N (interactive), --phase NN, --plan NN-MM modes.
/rollbackRestores codebase after failed multi-step /run or /evaluate using git stash/checkout/branch. Assesses scope for safest strategy and reports rollback details.
/rollbackRolls back the most recent database migration or to a specific version, with data loss warnings, explicit confirmation, transactional execution, schema verification, and status report.
/rollbackReverts to a previous Shipyard checkpoint via git: state-only (.shipyard/ files) or full (code + state). Supports --list flag and creates safety checkpoint first.
/rollbackSafely rollbacks a failed or unwanted feature by invoking /specswarm:rollback with optional flags (--dry-run, --keep-artifacts, --force).
Share bugs, ideas, or general feedback.
交互式回滚 Git 分支到历史版本,支持 reset 和 revert 两种模式。
💡 建议: 执行本命令前,建议先运行
/clear命令清理上下文,以获得更好的分析效果。
| 选项 | 说明 |
|---|---|
--branch <branch> | 要回滚的分支;缺省时交互选择 |
--target <rev> | 目标版本(commit Hash、Tag、reflog 引用);缺省时交互选择 |
--mode reset|revert | reset:硬回滚历史;revert:生成反向提交保持历史完整 |
--depth <n> | 在交互模式下列出最近 n 个版本(默认 20) |
--dry-run | 默认开启,只预览即将执行的命令 |
--yes | 跳过所有确认直接执行,适合 CI/CD 脚本 |
git fetch --all --prunegit branch -a(本地+远端,过滤受保护分支)git log --oneline -n <depth> + git tag --merged +
git reflog -n <depth>reset 或 revert--yes)reset:git switch <branch> && git reset --hard <target>revert:git switch <branch> && git revert --no-edit <target>..HEADgit push --force-with-lease(reset)或普通
git push(revert)特点:
--force-with-lease)才能更新远程适用场景:
命令:
git switch <branch>
git reset --hard <target>
git push --force-with-lease
特点:
适用场景:
命令:
git switch <branch>
git revert --no-edit <target>..HEAD
git push
git switch -c backup/<timestamp> 恢复main / master / production 等受保护分支且开启
reset 模式,将要求额外确认--force;如需强推,请手动输入
git push --force-with-lease| 场景 | 建议调用 |
|---|---|
热修补丁上线后发现 bug,需要回到 Tag v1.2.0 | --branch release/v1 --target v1.2.0 --mode reset |
| 运维同事误推了 debug 日志提交,需要生成反向提交 | --branch main --target 3f2e7c9 --mode revert |
| 调研历史 bug,引导新人浏览分支历史 | 全交互,dry-run |
# 纯交互:列出分支 → 选分支 → 列最近 20 个版本 → 选目标 → 选择模式 → 确认
# 默认 dry-run
# 指定分支,其他交互
# --branch feature/calculator
# 指定分支与目标 commit,并用 hard-reset 一键执行(危险)
git switch main
git reset --hard 1a2b3c4d
# 需要手动确认后执行 git push --force-with-lease
# 只想生成 revert 提交(非破坏式回滚),预览即可
git log --oneline -n 20 # 查看历史
# 确认目标后
git revert --no-edit v2.0.5..HEAD
reset 会改变历史,需要强推并可能影响其他协作者,谨慎使用revert 更安全,生成新提交保留历史,但会增加一次记录