agentleFS
jelbirtjelbirt/LLM-Skill-Build/git-undo/SKILL.md

git-undo

Skill1 starsChanged 3 months agoApache-2.0View on GitHub

Diagnose a git mistake and return the safe steps to undo it - the exact commands, what each does, what is reversible, and how to verify. Use whenever the user wants to undo, revert, roll back, or recover something in git, such as an accidental or wrong commit, committing to the wrong branch, an unwanted reset --hard, a bad merge or rebase, a force-push that lost work, a deleted branch, unstaging files, or "I think I lost a commit." Prefer this over ad-hoc git advice so recovery is state-aware and destructive steps are flagged and snapshotted first. If the repo is not directly accessible, ask the user to paste their git status and git reflog output.

  • Deletes or force-pushes
  • Commits and pushes

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do they want to keep the changes (just undo the commit) or discard them?

    line 34
  2. Distinctive:

    If the situation isn't in this table, reason from the diagnosis and the same safety rules below.

    line 55
  3. Very specific:

    Never rewrite shared history by default: If the bad commit was pushed to a shared branch, prefer git revert over reset/rebase.

    line 65
  4. Distinctive:

    The escape hatch: - if anything looks wrong, the snapshot branch or reflog SHA to return to.

    line 77
  5. Distinctive:

    Keep it calm and concrete.

    line 79

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

git-undo

Help the user safely undo a git mistake. Diagnose the real state first, then give the exact recovery commands - never guess, and never run a destructive command without flagging it and snapshotting first.

The user's description of the mistake (if any): $ARGUMENTS

1. Diagnose before recommending anything

Recovery depends entirely on the actual state. Establish it first.

If you can run git in the user's repo (e.g. Claude Code), run these read-only commands and read the output before saying anything:

  • git status - staged/unstaged/untracked, current branch, ahead/behind
  • git log --oneline -20 - recent commits
  • git reflog -20 - the safety net: where HEAD has been (this is what makes most "lost" work recoverable)

If you cannot access the repo (e.g. the chat app's sandbox), ask the user to paste the output of git status and git reflog. Do not recommend commands until you have it - the wrong assumption here can cause real data loss.

Also confirm the few facts that change the safe answer, if not already clear:

  • Is the bad work committed, or just staged/unstaged?
  • Has it been pushed? Is the branch shared with others?
  • Do they want to keep the changes (just undo the commit) or discard them?

2. Identify the situation

Map the diagnosis to one of these. Pick the safest command that fits.

SituationSafe recoveryReversible?
Discard changes to a tracked file (not yet committed)git restore {file}No - uncommitted edits are lost
Unstage a file (keep the edits)git restore --staged {file}Yes
Undo the last commit, keep changes stagedgit reset --soft HEAD~1Yes (commit is in reflog)
Undo the last commit, keep changes unstagedgit reset HEAD~1 (a.k.a. --mixed)Yes (reflog)
Fix the last commit's message / add a forgotten filegit commit --amendYes if not pushed (reflog)
Discard the last commit and its changessnapshot first, then git reset --hard HEAD~1Destructive - see step 3
Committed to the wrong branch (not pushed)git switch {correct-branch} then cherry-pick or, on the wrong branch, git reset --hard HEAD~1 after the commit is safely on the right branchMixed - snapshot first
Undo a commit that was already pushed/sharedgit revert {sha} (adds a new commit that reverses it - does not rewrite history)Yes, and safe for shared branches
Recover work after a bad reset --hard, rebase, or mergefind the good SHA in git reflog, then git reset --hard {sha} (or git merge --ff-only {sha})Recovers if within the reflog window
Undo a merge that isn't pushedgit reset --hard ORIG_HEAD (snapshot first)Recoverable via reflog
Restore a deleted branchfind its tip SHA in git reflog, then git branch {name} {sha}Yes
Recover files removed by git clean / deleted untracked filesusually not recoverable via git - say so honestly; suggest editor local history / OS trashOften no

If the situation isn't in this table, reason from the diagnosis and the same safety rules below.

3. Apply the safety discipline

This is the part that protects the user from making the mistake worse.

  • Classify every command you recommend as reversible or destructive. Call it out explicitly.
  • Before any destructive command (reset --hard, clean -fd, push --force, checkout .), create a snapshot the user can return to:
    • git branch backup/before-undo (marks the current commit), and note the current git reflog entry.
  • Never rewrite shared history by default. If the bad commit was pushed to a shared branch, prefer git revert over reset/rebase. If rewriting truly is the goal and the branch is private or coordinated, use git push --force-with-lease (not --force) so you don't clobber others' work.
  • Prefer modern, intent-clear commands: git restore / git switch over overloaded git checkout.
  • Don't auto-run destructive steps. Show the command, explain the blast radius, and ask the user to confirm (or run it themselves in the chat app).

4. Return the recovery

Give the user, in this order:

  1. What happened - one line naming the situation you diagnosed.
  2. The fix - the exact command(s), copy-pasteable, in order. Mark each reversible or destructive.
  3. What each command does - a short clause per command, so they learn, not just paste.
  4. How to verify - what git status / git log should show afterward.
  5. The escape hatch - if anything looks wrong, the snapshot branch or reflog SHA to return to.

Keep it calm and concrete. The user is likely stressed; precise, reassuring steps matter more than exhaustive theory.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.