Undoing a Commit Safely
Git revert.
Say a commit you made last week turned out to be a bad idea. You want to undo it. The safest way is git revert. It makes a new commit that does the exact opposite.

- A bad commit, already saved
- Undo it safely
- git revert
git revert
The log shows our latest commit added a spammy sale banner. Git revert, dash dash no edit, and head, which means the latest commit. Git creates a new commit, called revert, add sale banner. The log shows both, the mistake and its undo. And the banner line is gone from the file.
git log --oneline -n 3 95c7f8d (HEAD -> main) Add sale banner f63a17a Link to about page ef9c947 Add basic styles git revert --no-edit HEAD [main b895bf3] Revert "Add sale banner" Date: Mon Jan 5 09:34:15 2026 +0000 1 file changed, 1 deletion(-) git log --oneline -n 3 b895bf3 (HEAD -> main) Revert "Add sale banner" 95c7f8d Add sale banner f63a17a Link to about page cat index.html <h1>My Site</h1> <p>Welcome!</p> <a href="about.html">About</a>
Why revert is safe
Revert never deletes or changes history. It only adds a new commit on top. So it's completely safe, even for commits you've already shared with your team. Everyone can see what was undone, and why.
Summary
git revert undoes a commit by adding a new opposite commit. It's the safe undo for shared history. Next, its more powerful, and more dangerous, cousin.
Key takeaways- git revert <hash>
- Adds an undo commit
- Safe for shared work