What is git revert?

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."