home / skills / toilahuongg / shopify-agents-kit / git-undo

git-undo skill

/.claude/skills/git-undo

This skill helps you undo the last commit while keeping changes staged, enabling quick fixes to messages or added files before recommitting.

npx playbooks add skill toilahuongg/shopify-agents-kit --skill git-undo

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
473 B
---
name: git-undo
description: Undo the last commit while keeping changes staged. Use when you need to fix a commit message or add missing files.
disable-model-invocation: true
allowed-tools: Bash(git:*)
---

# Git Undo

Undo the last commit but keep changes staged.

1. Undo the last commit but keep the file changes in the staging area.
   - Command: `git reset --soft HEAD~1`
   - This allows you to fix the commit message or add missing files before committing again.

Overview

This skill provides a quick Git workflow to undo the most recent commit while preserving your file changes in the staging area. It’s designed for situations where the last commit needs a corrected message, missing files, or other small fixes before re-committing. The command is safe for local commits and keeps your working tree intact.

How this skill works

The skill runs a soft reset to move HEAD back one commit without touching the index or working directory. Specifically, it executes git reset --soft HEAD~1, which unstages the last commit but leaves its changes staged and ready to modify. After running it you can edit the commit message, add or remove files, and create a corrected commit.

When to use it

  • You made a typo or want to rewrite the last commit message.
  • You forgot to include one or more files in the last commit.
  • You want to split or combine changes from the last commit before re-committing.
  • You committed locally and realize the commit needs small adjustments before pushing.

Best practices

  • Ensure the commit you’re undoing has not been pushed to any shared remote; avoid rewriting history that others rely on.
  • Run git status after the reset to confirm changes remain staged as expected.
  • If you need to modify the staged changes, edit files then use git add to update the index before committing again.
  • For non-local commits already pushed, prefer revert or coordinate with your team before force-pushing rewritten history.

Example use cases

  • Fix a commit message: run the soft reset, then git commit -m "Corrected message".
  • Add a missed file: git reset --soft HEAD~1, git add missing-file, then git commit.
  • Split a combined change: soft reset, use git reset <file> to adjust staging, create multiple commits as needed.
  • Temporarily uncommit to run tests or linters against staged changes before finalizing the commit.

FAQ

Will this delete my file changes?

No. git reset --soft HEAD~1 keeps your working directory and the index intact; only the commit reference is moved back one step.

Is it safe if I already pushed the commit to remote?

Not recommended. Rewriting a commit that’s been pushed can cause problems for collaborators. Use git revert or coordinate a force-push with the team if necessary.