Git & GitHub Interview Question #55
What is git revert and when should it be used?
Undo & Recovery, Tags, Forks, Pull Requests & Code Review Mid-Level Intermediate
Quick Interview Answer
git revert creates a new commit that reverses the changes introduced by an earlier commit. The original commit remains in history.
Detailed Explanation
git revert creates a new commit that reverses the changes introduced by an earlier commit. The original commit remains in history.
This makes revert especially useful for shared branches because it preserves published history instead of rewriting it. Conflicts can still occur if later changes overlap with the commit being reverted.
Code Example
git revert <commit-id>
# Review the new history
git log --oneline