📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Git & GitHub Undoing Changes

Undoing Changes

5 min read Quiz at the end
Undo changes safely with revert, or rewrite history with reset --soft/--mixed/--hard.

Undoing Changes

# Amend last commit (before push)
git commit --amend -m "corrected message"
git commit --amend --no-edit  # keep message, add staged files

# Revert a commit (safe — creates new commit)
git revert abc1234
git revert HEAD~2             # revert 2 commits ago
git revert --no-commit HEAD~3..HEAD  # revert range

# Reset (dangerous — rewrites history)
git reset --soft HEAD~1       # undo commit, keep changes staged
git reset --mixed HEAD~1      # undo commit, unstage changes (default)
git reset --hard HEAD~1       # undo commit, DISCARD changes

# Recover lost commits with reflog
git reflog
git checkout abc1234
Topic Quiz · 2 questions

Test your understanding before moving on

1. What is the safest way to undo a pushed commit?
💡 git revert creates a new commit that undoes the changes — safe for shared branches.
2. What does git reset --soft HEAD~1 do?
💡 --soft undoes the commit, keeping all changes staged and ready to re-commit.