Claude Command: Git Rollback
Purpose: Safely and visually rollback a specified branch to an older version.
Defaults to read-only preview (--dry-run); actual execution requires --yes or interactive confirmation.
Usage
# Pure interactive: list branches → select branch → list recent 20 versions → select target → choose reset or revert → confirm
/git-rollback
# Specify branch, other interactive
/git-rollback --branch feature/calculator
# Specify branch and target commit, execute with hard-reset in one go (dangerous)
/git-rollback --branch main --target 1a2b3c4d --mode reset --yes
# Generate revert commit only (non-destructive rollback), preview
/git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
Options
| Option |
Description |
--branch <branch> |
Branch to rollback; interactively selected if omitted. |
--target <rev> |
Target version (commit hash, tag, or reflog reference); interactively selects recent --depth entries if omitted. |
--mode reset|revert |
reset: Hard rollback history; revert: Generate reverse commits keeping history intact. Prompts by default. |
--depth <n> |
List recent n versions in interactive mode (default 20). |
--dry-run |
Enabled by default, only preview commands to be executed. |
--yes |
Skip all confirmations and execute directly, suitable for CI/CD scripts. |
Interactive Flow
- Sync remote →
git fetch --all --prune
- List branches →
git branch -a (local + remote, filter protected branches)
- Select branch → User input or parameter
- List versions →
git log --oneline -n <depth> + git tag --merged + git reflog -n <depth>
- Select target → User inputs commit hash / tag
- Select mode →
reset or revert
- Final confirmation (unless
--yes)
- Execute rollback
reset: git switch <branch> && git reset --hard <target>
revert: git switch <branch> && git revert --no-edit <target>..HEAD
- Push suggestion → Prompt whether to
git push --force-with-lease (reset) or regular git push (revert)
Safety Guards
- Backup: Automatically records current HEAD in reflog before execution, recoverable with
git switch -c backup/<timestamp>.
- Protected branches: If protected branches like
main / master / production are detected with reset mode enabled, requires additional confirmation.
- --dry-run enabled by default: Prevents accidental operations.
- --force prohibited: No
--force provided; if force push needed, manually enter git push --force-with-lease.
Use Case Examples
| Scenario |
Command Example |
Hotfix patch deployed with bug, need to rollback to tag v1.2.0 |
/git-rollback --branch release/v1 --target v1.2.0 --mode reset |
| Ops colleague pushed debug logs by mistake, need to generate reverse commit |
/git-rollback --branch main --target 3f2e7c9 --mode revert |
| Research historical bugs, guide newcomers through branch history |
/git-rollback (full interactive, dry-run) |
Notes
- reset vs revert
- reset changes history, requires force push and may affect other collaborators, use with caution.
- revert is safer, generates new commits preserving history, but adds one more record.
- Embedded repositories often have large binary files; ensure LFS/submodule state consistency before rollback.
- If repository has CI forced validation, rollback may trigger pipelines automatically; confirm control policies to avoid accidental deployment of old versions.
1---
2name: git-rollback
3description: Interactively rollback Git branch to historical version; lists branches, versions, then executes reset/revert after confirmation
4disable-model-invocation: true
5allowed-tools: Read(**), Exec(git fetch, git branch, git tag, git log, git reflog, git checkout, git reset, git revert, git switch), Write()
6---
7
8# Claude Command: Git Rollback
9
10**Purpose**: Safely and visually rollback a specified branch to an older version.
11Defaults to **read-only preview (`--dry-run`)**; actual execution requires `--yes` or interactive confirmation.
12
13---
14
15## Usage
16
17```bash
18# Pure interactive: list branches → select branch → list recent 20 versions → select target → choose reset or revert → confirm
19/git-rollback
20
21# Specify branch, other interactive
22/git-rollback --branch feature/calculator
23
24# Specify branch and target commit, execute with hard-reset in one go (dangerous)
25/git-rollback --branch main --target 1a2b3c4d --mode reset --yes
26
27# Generate revert commit only (non-destructive rollback), preview
28/git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
29```
30
31### Options
32
33| Option | Description |
34| ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
35| `--branch <branch>` | Branch to rollback; interactively selected if omitted. |
36| `--target <rev>` | Target version (commit hash, tag, or reflog reference); interactively selects recent `--depth` entries if omitted. |
37| `--mode reset\|revert` | `reset`: Hard rollback history; `revert`: Generate reverse commits keeping history intact. Prompts by default. |
38| `--depth <n>` | List recent n versions in interactive mode (default 20). |
39| `--dry-run` | **Enabled by default**, only preview commands to be executed. |
40| `--yes` | Skip all confirmations and execute directly, suitable for CI/CD scripts. |
41
42---
43
44## Interactive Flow
45
461. **Sync remote** → `git fetch --all --prune`
472. **List branches** → `git branch -a` (local + remote, filter protected branches)
483. **Select branch** → User input or parameter
494. **List versions** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
505. **Select target** → User inputs commit hash / tag
516. **Select mode** → `reset` or `revert`
527. **Final confirmation** (unless `--yes`)
538. **Execute rollback**
54 - `reset`: `git switch <branch> && git reset --hard <target>`
55 - `revert`: `git switch <branch> && git revert --no-edit <target>..HEAD`
569. **Push suggestion** → Prompt whether to `git push --force-with-lease` (reset) or regular `git push` (revert)
57
58---
59
60## Safety Guards
61
62- **Backup**: Automatically records current HEAD in reflog before execution, recoverable with `git switch -c backup/<timestamp>`.
63- **Protected branches**: If protected branches like `main` / `master` / `production` are detected with `reset` mode enabled, requires additional confirmation.
64- **--dry-run enabled by default**: Prevents accidental operations.
65- **--force prohibited**: No `--force` provided; if force push needed, manually enter `git push --force-with-lease`.
66
67---
68
69## Use Case Examples
70
71| Scenario | Command Example |
72| --------------------------------------------------------------------------- | ---------------------------------------------------------------- |
73| Hotfix patch deployed with bug, need to rollback to tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
74| Ops colleague pushed debug logs by mistake, need to generate reverse commit | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
75| Research historical bugs, guide newcomers through branch history | `/git-rollback` (full interactive, dry-run) |
76
77---
78
79## Notes
80
811. **reset vs revert**
82 - **reset** changes history, requires force push and may affect other collaborators, use with caution.
83 - **revert** is safer, generates new commits preserving history, but adds one more record.
842. **Embedded repositories** often have large binary files; ensure LFS/submodule state consistency before rollback.
853. If repository has CI forced validation, rollback may trigger pipelines automatically; confirm control policies to avoid accidental deployment of old versions.
86
87---