What is git revert?

Why Interviewers Ask This

This is a classic screening question for Git & GitHub roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

git revert creates a new commit that undoes the changes made by a specified commit, without altering the existing history. It is the safe way to undo published commits. Unlike git reset which moves the branch pointer backward (rewriting history), git revert adds a new commit on top that applies the inverse of the specified commit's changes. Usage: git revert abc1234 — creates a new commit reverting abc1234; git revert HEAD — revert the last commit; git revert HEAD~3..HEAD — revert the last 3 commits (creates multiple revert commits). Options: --no-commit / -n — stage the revert changes without committing, letting you combine multiple reverts into one commit or review before committing. When to use revert vs reset: use git revert for commits already pushed to a shared/remote branch — it preserves history and doesn't break others' repos. Use git reset only for local, unpushed commits. The revert commit message explains what was undone: "Revert 'Fix login bug' — This reverts commit abc1234."

Pro Tip

Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Git & GitHub answers easy to follow.