↩️ Undoing
How to revert a commit in Git
Create a new commit that undoes the changes from a previous commit.
Revert the last commit
git revert HEADCreates a new commit that exactly reverses the last commit.
Revert a specific commit
git revert abc1234Reverts a specific commit by its hash. Find the hash with git log.
Revert without auto-committing
git revert --no-commit HEADStages the reversal but does not create the commit. Lets you inspect or modify first.
When to use: When you want to review or combine the revert with other changes.
Revert a range of commits
git revert HEAD~3..HEADReverts the last 3 commits, creating a new revert commit for each.