Undo a Git Mistake

Recover from a bad commit, force push, wrong branch, or lost work with a reversible plan and the exact commands, explained before you run them.

Help me recover from a git mistake without making it worse.

What I was trying to do: [THE GOAL]
What I ran: [THE EXACT COMMANDS, IN ORDER]
What happened instead: [THE OUTPUT OR THE STATE NOW]
Has this been pushed or shared: [YES/NO, and to which branch and whether anyone else has pulled]
Uncommitted work I cannot lose: [WHAT AND WHERE, or "none"]

Output of these, if you have them:
"""
[git status]
[git log --oneline -20]
[git reflog -30]
[git stash list]
"""

Work in this order:

1. **Stop and stabilize.** Tell me the single safest thing to do right now, before diagnosis, to make the current state recoverable. Usually that is a backup branch or a copy of the working tree. Give me that command first.

2. **Diagnose.** From the reflog and log, state where each piece of work currently lives, including anything that is unreachable but not yet garbage collected. Say plainly what is genuinely lost and what only looks lost.

3. **The plan.** The recovery steps in order, each with the exact command, what it changes, and how to verify it worked before moving to the next. Explicitly say which steps are reversible and which are not.

4. **Rewrite check.** If any step rewrites shared history, say so in bold terms, name who is affected, and give the alternative that does not rewrite (usually a revert commit) so I can choose knowingly.

5. **Verify.** The commands that confirm the recovery worked and nothing else moved.

6. **Prevention.** The one habit or config that would have made this mistake harmless.

Rules: prefer the reversible option every time both work, even when it is uglier. Never suggest a destructive command without first giving me the backup that makes it survivable. If the reflog output would tell you something you need and I did not paste it, ask for that specific command instead of guessing at my state.

How to use

The stabilize-first step is what makes this safe to use while panicking. Almost every git disaster is recoverable from the reflog, and almost every unrecoverable one became that way because of the second command someone ran while trying to fix the first. Paste the reflog output; it is the actual source of truth about where your commits went, and diagnosis without it is guesswork dressed as advice.

Originated fromStan SedberryUpdated
Gitintermediate

More coding prompts

Write the commit message for this change.

Diff:
"""
[PASTE THE STAGED DIFF]
"""

Why I made this change: [THE REASON, THE TICKET, THE BUG REPORT, or "you infer it"]
Convention: [Conventional Commits / this repo's existing style, pasted below / plain]
Recent commits from this repo, to match style:
"""
[PASTE 5-10 RECENT COMMIT SUBJECT LIN

Commit Message

Write a commit message that explains why the change was made, in Conventional Commits format, split into separate commits when needed.

Codingbeginner
Handler code, routes, and models:
"""
[PASTE THE ROUTE DEFINITIONS, HANDLERS, REQUEST AND RESPONSE TYPES, VALIDATION SCHEMAS, AND MIDDLEWARE]
"""

Generate an OpenAPI 3.1 specification from the code above.

API name, version, and base URL: [DETAILS]
Auth scheme: [BEARER JWT / API KEY / OAUTH / SESSION COOKIE, and where it is enforced]
Con

OpenAPI Spec From Code

Generate an accurate OpenAPI 3.1 spec from handler code, including error responses and auth, with gaps flagged instead of invented.

Codingintermediate
Infrastructure code to review:
"""
[PASTE THE TERRAFORM, CLOUDFORMATION, PULUMI, OR KUBERNETES MANIFESTS. INCLUDE THE PLAN OUTPUT IF YOU HAVE IT.]
"""

Review the infrastructure code above as the person who will be paged when it breaks.

Environment: [PROD / STAGING / DEV] and what runs on it: [WORKLOAD]
What this change is meant to do: [

Infrastructure as Code Review

Review Terraform, CloudFormation, or Kubernetes manifests for blast radius, security defaults, state risk, and what the plan will really do.

Codingadvanced

Search prompts

Find a prompt by title, description, tag, or category.