On This Page
Git Reset vs Revert vs Checkout: Difference Explained
Quick Answer: All three commands undo changes in Git, but operate on different scopes:
git resetrewinds history by moving the branch pointer backwards (best for local, unpushed commits).git revertcreates a new commit that undoes a previous commit’s changes (best for pushed/public commits).git checkoutmovesHEADto a different branch/commit or restores working tree files without altering commit history.
Comparison Cheat Sheet
| Command | Moves Branch Pointer? | Creates New Commit? | Safe for Pushed Commits? | Target Scope |
|---|---|---|---|---|
git reset | ✅ Yes | ❌ No | ❌ No (rewrites history) | Local branch pointer & index |
git revert | ❌ No | ✅ Yes | ✅ Yes (100% safe for remote) | Create inverse commit |
git checkout | ❌ No | ❌ No | ✅ Yes | Switch branch / inspect file |
1. git reset — Rewind Branch History
git reset moves your current branch pointer backward in time.
# Soft: Rewind branch pointer, keep code staged
$ git reset --soft HEAD~1
# Mixed (default): Rewind branch pointer, unstage code
$ git reset --mixed HEAD~1
# Hard: Rewind branch pointer & erase all uncommitted edits
$ git reset --hard HEAD~1
When to use: Local commits you haven’t pushed to GitHub yet. Read /git-add to understand how reset affects index entries.
2. git revert — Undo Changes Safely on Shared Branches
Instead of erasing history, git revert calculates the inverse diff of a commit and commits that inverse as a brand-new commit.
# Undo the last commit safely on public branches
$ git revert HEAD
# Undo a specific past commit
$ git revert a1b2c3d
When to use: Undoing changes that have already been pushed to a remote repository shared with team members.
3. git checkout — Switch Context or Inspect Files
git checkout alters where HEAD points or replaces files in your working directory.
# Switch active branch
$ git checkout feature
# Inspect a past commit in detached HEAD state
$ git checkout a1b2c3d
# Restore a single modified file to its last committed state
$ git checkout -- src/app.js
When to use: Navigating between branches or inspecting historical snapshots. Read /git-checkout for deeper details.