Git Command Generator

Next

Every engineer has Googled “how do I undo the last commit” at least twice. Instead of guessing between reset --soft, reset --mixed and reset --hard, pick the task from a list and the generator prints the exact command, with your branch, commit SHA or tag name filled in.

How to generate a Git command

  1. 1

    Pick the task

    Undo last commit, amend message, rebase onto main, cherry-pick, force-reset to remote, tag a release…

  2. 2

    Fill in the parameters

    Branch name, commit SHA, tag: only the fields each task needs.

  3. 3

    Read the command

    The tool assembles the right flags in the right order.

  4. 4

    Copy and run

    Paste into your terminal; the command is a drop-in line, not pseudo-code.

Tasks it covers

Task Command produced
Undo last commit (keep staged) git reset --soft HEAD~1
Amend last commit message git commit --amend -m "…"
Discard all uncommitted changes git restore . + git clean -fd
Create + switch to a new branch git checkout -b feature/x
Delete branch locally + remotely git branch -d x + git push origin --delete x
Sync feature branch with main git fetch origin + git rebase origin/main
Cherry-pick a commit git cherry-pick <sha>
Revert a commit (safe) git revert <sha>
Tag and push a release git tag -a v1.0.0 -m "…" + git push origin v1.0.0
Force-reset local to remote git fetch origin + git reset --hard origin/main

Commands marked safe vs destructive

  • Safe (rewind-able): commit, switch, checkout -b, revert, tag.
  • Destructive on local working tree: restore ., clean -fd, reset --hard.
  • Destructive on shared history: push --force, filter-repo, rebase on branches others use.

Tip: dry-run risky commands

Before git clean -fd, run git clean -nd, the -n flag prints what would be deleted without deleting. Same idea for git rm: read git status first.

Frequently Asked Questions

Because “undo” means different things. reset --soft HEAD~1 keeps your changes staged so you can re-commit; --mixed unstages them; --hard throws them away. The generator lets you pick the intent instead of memorising flags.

revert creates a new commit that undoes an old one, safe on a shared branch because history is preserved. reset rewinds the branch pointer, which changes history and requires a force push if the branch is shared.

Yes, for the “remove a file from all history” task. It is safer and faster than the deprecated filter-branch; you must install it separately (brew install git-filter-repo or via pip).

No. It only prints the command, running it is always your decision, so you can review flags and context before touching the repo.

Related Tools

Tool available in other languages