Repaso
Español
Maven, Git & SDLCIntermediateVCS-13

What is the difference between git reset and git revert for undoing a commit?

Options

  1. They are identical in the effect they have on history
  2. reset rewrites history; revert adds an undoing commit (Correct option)
  3. revert deletes the whole repository from the disk
  4. reset only works on remote branches, never local

Answer

reset moves the branch back, rewriting history (risky if already pushed); revert creates a NEW commit that undoes the old one, safe for shared branches

Why

git reset --hard <commit> moves your branch pointer back and discards later commits and changes. Fine for local work, but if others already have those commits, you create a mess (it rewrites history).

git revert <commit> adds a new commit with the opposite changes. History stays intact, so it is the safe way to undo something already pushed to a shared branch like main.

git revert 3f2a9c1        # safe on shared branches
git reset --hard HEAD~1   # local only: drops last commit and changes

Remember

Shared branch: revert. Local mess: reset.

Key terms

Practice this question in Repaso