git revert creates a new commit that undoes a previous commit — it doesn't rewrite history. This makes it safe to use on shared/public branches where rewriting history would break others' repos.
git revert HEAD # undo last commit (opens editor for message)
git revert HEAD --no-edit # undo last commit, keep generated message
git revert abc1234 # undo a specific commit by hash
git revert HEAD~2..HEAD # undo last 2 commits (creates 2 revert commits)
| git reset | git revert | |
|---|---|---|
| Rewrites history | Yes | No |
| Safe for shared branches | ❌ Never | ✅ Always |
| Creates new commit | No | Yes |
A bug was introduced in the last commit. Use git revert HEAD --no-edit to create a revert commit. The file should go back to its previous content.
Click "Run" to execute your code.