Git Revert
git revert undoes a commit by making a new commit that reverses its changes. The old commit stays in the history.
Because nothing is removed, revert is the safe way to undo a commit that you have already pushed.
Revert the last commit
git revert HEAD --no-edit
[main 4572bd3] Revert "Add a thank you line"
Date: Thu Nov 5 10:58:06 2026 +0100
1 file changed, 2 deletions(-)
git log --oneline
4572bd3 Revert "Add a thank you line"
bf9f310 Add a thank you line
5091107 Add blue style
5e4276a Update README
5740ce0 Add README
f132bf3 First release of Hello World!
Revert an Older Commit
Use the hash, or a name like HEAD~2: git revert 5e4276a. Without --no-edit, Git opens your editor so you can change the message.