Git Reset vs Revert — Undo Changes Safely
Both reset and revert undo changes, but they work very differently. Use the builder above to construct the right command with safe defaults.
Build git commands visually or browse the cheat sheet. Select an operation, fill in parameters, and copy the result.
Initialize Repository
Create a new Git repositorygit init
Quick Tips
- Use
git switchinstead ofgit checkoutfor switching branches (Git 2.23+) - Prefer
--force-with-leaseover--forceto avoid overwriting others' work - Use
git reflogto recover lost commits
git reset — rewrite history
git reset moves the branch pointer backward, effectively removing commits from history. --soft keeps changes staged, --mixed (default) keeps changes unstaged, --hard discards everything. Because it rewrites history, only use reset on unpushed commits.
git revert — safe undo
git revert creates a new commit that undoes the changes from a previous commit. The original commit stays in history. This is safe to use on shared branches because it does not rewrite history. Use --no-edit to accept the default revert message.
Which should I use?
Use revert for commits that have been pushed to a shared branch. Use reset for local unpushed commits where you want a clean history. When in doubt, use revert — it is always safe.
Frequently Asked Questions
Can I undo a git reset?
Yes, using git reflog. Find the commit hash before the reset and run git reset --hard <hash>. Reflog keeps a history of HEAD changes for about 90 days.
What does git reset --soft do?
git reset --soft HEAD~1 undoes the last commit but keeps all changes staged. This is useful when you want to amend or restructure a commit without losing any work.
Related Generate Tools
QR Code Generator
Generate customizable QR codes from text or URLs
Color Palette Generator
Generate harmonious color palettes using color theory algorithms
Box Shadow Generator
Design CSS box shadows visually with multiple layers, presets, and live preview
Flexbox Generator
Build CSS flexbox layouts visually with live preview, item config, and presets