https://github.com/sulthonzh/gitpanic
Interactive CLI that diagnoses git mistakes and guides you through recovery. Reflog-powered undo wizard.
https://github.com/sulthonzh/gitpanic
cli developer-tools git recovery reflog terminal undo wizard
Last synced: 8 days ago
JSON representation
Interactive CLI that diagnoses git mistakes and guides you through recovery. Reflog-powered undo wizard.
- Host: GitHub
- URL: https://github.com/sulthonzh/gitpanic
- Owner: sulthonzh
- License: mit
- Created: 2026-05-24T15:57:55.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-06-24T21:15:19.000Z (8 days ago)
- Last Synced: 2026-06-24T23:07:41.300Z (8 days ago)
- Topics: cli, developer-tools, git, recovery, reflog, terminal, undo, wizard
- Language: TypeScript
- Size: 340 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gitpanic
Interactive CLI that diagnoses git mistakes and guides you through recovery — like `git reflog` but human-friendly.
## Why gitpanic?
Every developer has panicked after a bad git operation. Stack Overflow's top git questions are all "how do I undo...":
- "How to undo last commit" — 16k+ upvotes
- "How to undo git push" — 5k+ upvotes
- "How to recover deleted branch" — 3k+ upvotes
- "How to undo git merge" — 2k+ upvotes
`git reflog` is powerful but intimidating. `gitpanic` provides an interactive wizard that:
1. **Auto-detects** common git disasters from your repository state
2. **Diagnoses** the problem in plain English
3. **Guides** you through recovery with risk levels and confirmations
4. **Protects** you by never executing without confirmation
## Installation
```bash
npm install -g gitpanic
```
Or use with npx:
```bash
npx gitpanic
```
## Usage
### Basic Scan
Run `gitpanic` in any git repository:
```bash
$ gitpanic
🔍 Analyzing your git state...
⚠️ Found 1 potential issue:
1. 🟢 Uncommitted Changes
You have 3 uncommitted files. 1 staged. 2 modified.
Confidence: 100%
Select an issue to fix [1-1] or press Enter to exit: 1
🔧 Recovery options for: Uncommitted Changes
1. ✅ Stash changes
Save your changes to apply later
Risk: safe
Steps:
- git stash push -m "WIP"
2. ✅ Commit changes
Create a commit with your changes
Risk: safe
Steps:
- git add .
- git commit -m "WIP"
3. ⚠️ Discard all changes
Remove all uncommitted changes (DANGEROUS)
Risk: high
Steps:
- git reset --hard HEAD
- git clean -fd
Select a recovery option [1-3]: 1
⚠️ Confirm: "Stash changes"? This can be undone. [y/N]: y
🚀 Executing recovery...
✅ Recovery complete!
```
### Dry Run Mode
Preview what would happen without making changes:
```bash
gitpanic --dry-run
```
### Timeline
See your recent git operations in plain English — way more readable than `git reflog`:
```bash
$ gitpanic timeline
Recent git operations:
↗ checkout main → fix/login-bug (a1b2c3d, 2m ago)
✓ commit add login validation (e4f5g6h, 5m ago)
✓ commit wip: login form (i7j8k9l, 12m ago)
↗ checkout develop → main (m0n1o2p, 1h ago)
↓ pull Fast-forward (q3r4s5t, 2h ago)
```
Options:
```bash
gitpanic timeline --limit 10 # Show last 10 operations (default: 20)
gitpanic timeline --json # JSON output for scripting
gitpanic timeline --markdown # Markdown table for docs/PRs
```
Great for answering "wait, what did I just do?" without deciphering raw reflog output.
### Non-Interactive Mode
For use in scripts (requires manual implementation of recovery options):
```bash
gitpanic --non-interactive
```
## Detected Disasters
`gitpanic` can detect and recover from:
| Disaster | Description | Severity |
|----------|-------------|----------|
| **Detached HEAD** | You're in detached HEAD state | Medium |
| **Deleted Branch** | A branch was recently deleted | High |
| **Force Push** | You recently force-pushed (may have overwritten commits) | High |
| **Botched Merge** | Merge in progress or recently aborted | Medium |
| **Accidental Commit** | Recent commit that might be a mistake | Low |
| **Uncommitted Changes** | Files that need to be committed | Low |
| **Wrong Branch Commit** | Commit that might belong on main/master | Medium |
## Recovery Options
Each disaster comes with multiple recovery strategies with different risk levels:
- ✅ **Safe**: Can be easily undone (e.g., stash, soft reset)
- ⚡ **Medium**: May require manual intervention (e.g., cherry-pick)
- ⚠️ **High**: Destructive, cannot be undone (e.g., hard reset, clean)
## How It Works
1. **Analysis Phase**: `gitpanic` analyzes your git state using:
- `git reflog` to find recent operations
- `git status` to check for uncommitted changes
- `git log` to examine commit history
2. **Detection Phase**: Multiple detectors scan for patterns:
- Recent commits (< 2 minutes) → accidental commit?
- Detached HEAD state → need to reattach?
- Force push in reflog → overwritten commits?
- Branch deletion in reflog → can be recovered?
- MERGE_HEAD file → merge conflict?
- Untracked/modified files → need to commit?
3. **Recovery Phase**: For each detected disaster, provide:
- Clear explanation of what happened
- Multiple recovery options with risk levels
- Step-by-step command preview
- Confirmation before execution
## Examples
### Recover a Deleted Branch
```bash
$ gitpanic
⚠️ Found 1 potential issue:
1. 🔴 Deleted Branch
Branch "feature/login" was deleted 45 seconds ago.
Confidence: 90%
Select an issue to fix [1-1]: 1
🔧 Recovery options for: Deleted Branch
1. ✅ Restore branch "feature/login"
Recreate the branch from the deleted commit
Risk: safe
Steps:
- git branch feature/login abc1234
- git checkout feature/login
Select a recovery option [1-1]: 1
⚠️ Confirm: "Restore branch \"feature/login\""? This can be undone. [y/N]: y
✅ Recovery complete!
```
### Undo an Accidental Commit
```bash
$ gitpanic
⚠️ Found 1 potential issue:
1. 🟢 Accidental Commit
You just committed "typo fix" 12 seconds ago.
Confidence: 80%
Select an issue to fix [1-1]: 1
🔧 Recovery options for: Accidental Commit
1. ✅ Undo commit, keep changes staged
Remove the commit but keep your changes ready to commit
Risk: safe
Steps:
- git reset --soft HEAD~1
Select a recovery option [1-1]: 1
⚠️ Confirm: "Undo commit, keep changes staged"? This can be undone. [y/N]: y
✅ Recovery complete!
```
### Fix Detached HEAD
```bash
$ gitpanic
⚠️ Found 1 potential issue:
1. 🟡 Detached HEAD
You are in detached HEAD state. Changes here can be lost.
Confidence: 100%
Select an issue to fix [1-1]: 1
🔧 Recovery options for: Detached HEAD
1. ✅ Reattach to previous branch
Switch back to main
Risk: safe
Steps:
- git checkout main
Select a recovery option [1-1]: 1
⚠️ Confirm: "Reattach to previous branch"? This can be undone. [y/N]: y
✅ Recovery complete!
```
## Development
```bash
# Clone
git clone https://github.com/sulthonzh/gitpanic.git
cd gitpanic
# Install
npm install
# Build
npm run build
# Test
npm test
# Run local
node dist/cli.js
```
## License
MIT
## Contributing
Contributions welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
## Similar Tools
- [git-undo](https://github.com/zhangela/git-undo) - Python-based git undo
- [ohshitgit.com](https://ohshitgit.com) - Reference site for git disasters
- [git-reflog](https://git-scm.com/docs/git-reflog) - Raw git reflog reference
**What makes gitpanic different?**
- Interactive wizard UI (not just commands)
- Auto-detects problems (no manual diagnosis needed)
- TypeScript (modern, type-safe)
- Recovery preview with risk levels
- Safety-first with confirmations