deftools.io DevOps & CLI

🔙 Git Undo Helper

Find the right git command to undo mistakes: wrong branch commits, accidental pushes, lost branches, bad merges, unstaging, and more.

Filter:
Git command
 

About this tool

We've all done it — committed to the wrong branch, pushed something we shouldn't have, or lost work to a bad merge. This tool helps you find the right git command for your situation. Pick what happened from the list, optionally fill in details (branch names, commit hashes), and get the exact commands with explanations.

Every scenario includes a danger rating: safe (no destructive actions), careful (rewrites local history — use with caution), and dangerous (permanently deletes changes or rewrites shared history).

Pro tip: When in doubt, reach for git reflog first. Git keeps a log of every HEAD change for weeks — most "lost" commits can be recovered from the reflog.

FAQ

Which scenarios are covered?

The tool covers 20+ common undo situations: wrong branch commit, amend messages, undo pushed commits, unstage files, discard local changes, undo merges (local and pushed), recover deleted branches and lost commits, split commits, fix authorship, remove files from commits, reorder/squash commits, abort in-progress operations, undo force pushes, undo tag pushes, and more.

Can these commands destroy my work?

Commands marked dangerous (red badge) can permanently delete uncommitted changes or rewrite shared git history. Always review the explanation before running anything. The safest undo tool is <code>git revert</code> — it creates a new commit that reverses the changes without destroying history.

What if I already pushed the mistake?

Prefer <code>git revert</code> for pushed commits — it adds a reversal commit and keeps history intact. Avoid <code>git reset --hard</code> + force push on shared branches, as it rewrites history for everyone else. If you must force push, warn your team first.

How do I recover something I deleted yesterday?

Run <code>git reflog</code> to see a timeline of every HEAD change. Find the commit hash before the deletion, then run <code>git checkout &lt;hash&gt; -b recovered-branch</code>. Reflog entries expire after ~90 days by default.

Related devops & cli tools

Copied!