Git Command Finder

Undo, recover, and fix, with the danger spelled out.

Type what you want to do, such as "undo my last commit" or "recover a deleted branch", and get the exact git command, what it does, how to undo it, and what changes if you already pushed. Forty-two scenarios, an undo decision tree, and the reflog safety net.

Zero retention: your data never leaves this browser. Verify it yourself in DevTools

Loading the toolbox.

About Git commands

How Can You Verify That Nothing Leaves This Browser?

You do not have to take our word that your data stays here. Developer tools show every request a page makes, so you can watch this page work and confirm that nothing is sent. The check takes under a minute.

  1. Open your browser developer tools with F12, or Cmd+Option+I on a Mac, and select the Network tab.
  2. Reload the page and let it finish. You will see the page's own files, its web fonts, and one anonymous page-view request. Nothing has been typed yet, so none of them can contain your data.
  3. Click the clear icon in the Network tab so that the log is empty.
  4. Use the tool with your own input.
  5. Look at the Network tab again. It is still empty. For extra proof, turn on offline mode after the page loads and the tool keeps working.

Only two things can add a line to that log, and neither carries your data. Submitting the feedback form sends the vote and comment you typed. Typing characters in a script the page has not displayed yet, such as Cyrillic or Greek, can make the browser fetch the matching font file, and that request names only the font.

The production site also sends a Content-Security-Policy header that tells your browser to refuse connections to anywhere except this site and the anonymous analytics endpoint, so a coding mistake could not quietly send your data elsewhere.

What Does the Git Command Finder Do?

Git has a command for almost every mistake, but the right one depends on details that are easy to get wrong in a hurry: whether the change was committed, whether it was pushed, and whether you want to keep the edits. This finder starts from what you want to do, written in plain words, and answers with the command, a line explaining each part, how to reverse it, and what to do differently when the commit is already on a shared branch.

It covers forty-two scenarios in eight groups: undoing commits and changes, rewriting commits, branches, working with the remote, stashes, files, reading history, and recovering lost work. The commands use the modern porcelain introduced in Git 2.23, git switch and git restore, instead of the overloaded git checkout, so each command does one thing.

How Do the Danger Badges Work?

Every scenario carries one of three badges, decided by what the command can lose rather than by how unfamiliar it looks.

  • Safe commands read history, add a new commit, or create a name such as a branch or a stash. Nothing that existed before is changed. git revert, git bisect, and git reflog are safe.
  • Careful commands rewrite local history or move changes between your files, the staging area, and commits. What they replace is still reachable through the reflog or the stash, so a mistake can be reversed. Amending, squashing, and interactive rebase are careful.
  • Destructive commands can discard uncommitted work, delete untracked files, or overwrite history that other people already have. git reset --hard, git restore on edited files, git clean -fd, and force pushes are destructive, and each shows a red warning that says exactly what cannot come back.

The key fact behind the badges is that git only protects what was committed. Edits sitting in your working tree were never recorded anywhere, so a command that overwrites them has no undo.

How Should You Undo a Commit?

It depends on one question above all: has anyone else got the commit? If it is only in your clone, you can rewrite it. git reset --soft HEAD~1 takes back the last commit and keeps its changes staged, git commit --amend fixes its message or adds a forgotten file, and an interactive rebase edits, squashes, or drops older commits.

Once a commit is pushed to a shared branch, rewriting it forces everyone else to repair their clones. The finder sends every pushed case to git revert, which adds a new commit that cancels the old one and needs no force push. A merge commit needs git revert -m 1 so git knows which parent to keep. If you truly must rewrite a shared branch, use git push --force-with-lease, which refuses to overwrite commits you have not seen.

How Does the Undo Decision Tree Work?

When you are not sure which scenario fits, the decision tree asks short yes or no questions and stops as soon as it can recommend one. It asks at most five:

  1. Have you committed the change?
  2. If not, is it staged, and do you want to keep the edits? If so, has it been pushed or shared?
  3. Is it a merge commit?
  4. Is it your most recent commit, or an older one?
  5. Do you only need to fix the message or add a file, and do you want to keep the changes?

The answer is the same scenario card you would find by searching, with its command, its badge, and its undo note.

What Is the Reflog and Why Is It a Safety Net?

The reflog is a local diary of every position HEAD and each branch has had. Every commit, reset, rebase, merge, amend, and switch adds an entry, so after almost any accident you can run git reflog, find the line from before the mistake, and get back to it. The safest move is to name that state first with git branch rescue HEAD@{2}, inspect it, and only then reset to it.

The reflog has limits worth knowing. It lives only in your clone and is never pushed. It records commits, not uncommitted edits. And its entries expire: by git's documented defaults, gc.reflogExpire keeps reachable entries for 90 days and gc.reflogExpireUnreachable keeps unreachable ones for 30 days, after which garbage collection may prune the objects. Dropped stashes and deleted branches can also be found with git fsck until then.

Which Scenarios Are Covered?

  • Undo: undo or drop the last commit, unstage all or part of a file, discard changes, delete untracked files, undo a merge or a pull, and abort a merge, rebase, or cherry-pick.
  • Commits: amend the message, add a forgotten file, change the author, squash, fix or drop an older commit, split a commit, revert a pushed commit or merge, and cherry-pick.
  • Branches and remote: move commits to a new or the right branch, rename, delete, and clean up merged branches, leave detached HEAD, force push safely, match the remote, pull with rebase, and sync a fork.
  • Stash, files, and history: stash and restore work, recover a dropped stash, stop tracking a file, restore an old version, recover an overwritten file, purge a leaked secret from history, manage tags, read diffs, blame a line, and bisect a regression.
  • Recovery: get back a deleted branch, undo a hard reset or a rebase, and find a lost commit.

Does This Page Run Git or See My Repository?

No. It is a reference that runs entirely in your browser. It never runs git, never reads your files, and sends nothing anywhere; the commands are text for you to copy into your own terminal. Replace placeholders such as <sha>, feature-x, and main with your own names before running them. Other tools in the Commands lane build tar, ffmpeg, OpenSSL, and Dockerfile commands the same way.

What Other Tools Are in the Commands Lane?

  • tar: Paste a tar command to have every flag explained and the -C ordering trap flagged, or tick what you want and copy the command.
  • ffmpeg: Pick a task to get an explained ffmpeg command, decode a pasted one, or work out the bitrate for a target file size.
  • OpenSSL: Explained OpenSSL commands for keys and CSRs with SANs, self-signed certificates, inspection, PEM, PFX, and DER conversion, and chain checks.
  • systemd: Generate a systemd service and timer with restart, user, environment, and hardening options, convert cron to OnCalendar, and copy the install commands.
  • Dockerfile: Generate a multi-stage Dockerfile for Node, Python, static sites, or Go with a non-root user and healthcheck, plus a .dockerignore and a paste linter.

Elsewhere in the toolbox: UUID, .gitignore, CSP, .htaccess, and more on the 2toolbox home page. Part of the 2suite.io privacy-first ecosystem.

Frequently Asked Questions

How do I undo my last commit but keep the changes?

Run git reset --soft HEAD~1. The commit is removed from the branch and its changes stay staged. If it was already pushed, use git revert instead.

Can I get back a branch I deleted?

Usually, yes. Find its last commit in git reflog and run git branch with the old name and that commit id. The commits stay until garbage collection prunes them.

Is git reset --hard ever recoverable?

Committed work is: find the earlier position in git reflog and reset back to it. Uncommitted edits that the reset overwrote are not recoverable from git.

Why use --force-with-lease instead of --force?

Plain --force overwrites the remote branch no matter what. --force-with-lease refuses if someone pushed commits you have not fetched, so you cannot silently delete their work.

Why does the page use git restore and git switch?

Since Git 2.23 they split the old git checkout into two clear commands, one for files and one for branches, which makes mistakes less likely.

Was this helpful?