Git revert is used to undo a committed change by creating a new commit that reverses a previous commit. It keeps the repository history intact and is safe for public branches.
The basic syntax of git revert requires a commit hash to identify which commit should be undone.
// Revert a specific commit using its hash
git revert <commit-hash>
// Revert the most recent commit
git revert HEAD
// Revert multiple commits using a range
git revert <commit-hash>^..<commit-hash>
A new commit is created that reverses the changes. The commit history remains intact and collaboration is unaffected.
Think of git revert as applying an opposite patch. Instead of removing history, it appends a corrective step.