The safe way to back out a change that's already public.
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.
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.'
git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
git revert (--continue | --skip | --abort | --quit)| Flag | What it does |
|---|---|
-n, --no-commit | Stage 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-edit | Use the auto-generated commit message without launching the editor. |
-s, --signoff | Append Signed-off-by: trailer. |
reset + force-push).$ git revert <sha>$ git revert -n abc..def && git commit -m 'revert range abc..def'$ git revert -m 1 <merge-sha>revert over reset. Always.revert a merge and later want to bring those changes back, you can't just re-merge — you'll need to revert the revert, or rebase. Plan before pulling the trigger.-m 1) effectively kills future merges from that branch — the revert says 'these changes don't belong here'. Re-introducing them requires revert <revert-sha>.git revert --continue.Hit each option, then Check answers. Score is recorded; Next is always open.