thinkhard.SI

Prompt repository Engineering & code

Fix a git mistake without losing work

You committed to the wrong branch, lost changes in a rebase or pushed something you should not have, and need safe steps to recover.

Registry no.
ENG-028
Collection
Engineering & code
Laid out for
Any chat model
Score
10 out of 10
Blanks to fill
4
Added

Engineering & codeAny chat

The prompt

Score 10 of 10, Excellent

Use it when You committed to the wrong branch, lost changes in a rebase or pushed something you should not have, and need safe steps to recover.

  • {{intent}}
  • {{what_happened}}
  • {{shared_state}}
  • {{git_output}}
Full prompt and why it works
Prompt
Help me recover from a git mistake without losing any work, so that I can carry on from a clean state. I will run your commands myself in a terminal, one at a time, so they need to be exact.

What I was trying to do: {{intent}}
What I did, as best I remember: {{what_happened}}
Whether the commits were pushed, and who else works on the branch: {{shared_state}}

Output of git status, git log --oneline --graph --all -n 20 and git reflog -n 20:
"""
{{git_output}}
"""

Reply with:
1. What happened, in two or three sentences, based on the output above.
2. A safety step first: the command that creates a backup branch or tag of the current state, so nothing can be lost while we fix it.
3. The recovery steps, numbered, one command per step, each with what it does and what I should see afterwards.
4. How to check the result: the command that shows the branch is right, and what it should show.

Use the fewest commands that do the job, and explain each one in a plain sentence, because I need to understand what I am running. Make sure the backup step comes before anything that moves or deletes commits.

For example, the form of one step: "3. git cherry-pick a1b2c3d (copies your commit onto this branch; you should see 1 file changed)."

Avoid commands that rewrite shared history, such as git push --force or a rebase of a pushed branch, unless the branch is mine alone. If one is truly needed, say so plainly, use git push --force-with-lease instead, and tell me who to warn first. Do not suggest git reset --hard, git clean, or discarding changes to files until the backup step is done. Base every step on the output I pasted, not on what usually happens. If the output does not show the commits or changes I mention, say what is missing and ask me to run a specific command rather than guessing commit hashes. If a password, key or token was committed and pushed, tell me to revoke it first, because removing it from history does not make it safe again.

Variables

{{intent}}
What you meant to do, for example "commit my fix to a new branch, not to main".
{{what_happened}}
The commands you ran, in order, as best you remember.
{{shared_state}}
Whether the commits were pushed and whether anyone else works on that branch, for example "pushed to main, which the whole team uses".
{{git_output}}
The output of git status, git log --oneline --graph --all -n 20 and git reflog -n 20, run in the repository.

Why it works

  • What to avoid. Force pushes, hard resets and history rewrites on shared branches are ruled out or flagged, and nothing destructive comes before a backup branch.
  • Background facts. Every step rests on your actual status, log and reflog, which show where commits that look lost really are.
  • If unsure. Missing commits lead to a request for more output rather than guessed hashes, and a pushed secret is revoked first, since rewriting history does not undo the leak.

How to use it

  1. Press Fill in variables and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/git-mistake-recovery

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "git-mistake-recovery"}, or just ask for it by name.