Progress:
TIER 1 · MODULE 14· Basics

git revert

The safe way to back out a change that's already public.

🎯 What & why

Create a new commit that undoes the changes of a previous one. The history is preserved; the cancellation is appended. The right tool when you need to back out a change that's already been pushed.

🧠 Mental model

Revert computes the reverse diff of <commit> and applies it on top of HEAD as a new commit. The original commit stays in history. Reverting a merge requires -m <parent-number> because Git doesn't know which side to consider the 'mainline.'

🛠️ Synopsis

git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
git revert (--continue | --skip | --abort | --quit)

🎚️ Switches & options

FlagWhat it does
-n, --no-commitStage the reverse change without creating the commit. Useful when reverting multiple commits as one.
-m <n>Specify mainline parent for reverting a merge. -m 1 is usually what you want.
--no-editUse the auto-generated commit message without launching the editor.
-s, --signoffAppend Signed-off-by: trailer.

💡 Use cases

🧪 Examples

Revert a single commit.
$ git revert <sha>
Revert a range without committing each one.
$ git revert -n abc..def && git commit -m 'revert range abc..def'
Revert a merge commit (mainline = first parent).
$ git revert -m 1 <merge-sha>

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.