GIT-REVERT(1)
π git-revert(1) β the "undo that commit, but politely" manual
okay so bestie, welcome to git-revert(1), straight out of the Git Manual β¨ this is the page about taking a commit that already happened and gently reversing it with a brand-new commit. no history rewriting, no drama, just vibes and counterspell commits π«Ά
β¨ NAME β¨
git-revert β revert some existing commits π
π¦ SYNOPSIS π¦
git revert [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>...
git revert (--continue | --skip | --abort | --quit)
two whole modes, bestie: the "revert some stuff" line, and the "sequencer damage control" line π
π DESCRIPTION π
okay so picture this: you hand it one or more existing commits, and git revert reverses the changes that the related patches introduce, then records some new commits that record that reversal. iconic behaviour honestly. the one catch β your working tree has to be clean (no modifications from the HEAD commit), so no sneaky half-finished edits lying around π
β οΈ note time, and this one lowkey matters:git revertis the tool for recording new commits that reverse the effect of some earlier commits (often just one faulty one, we've all been there π). if what you actually want is to throw away all uncommitted changes in your working directory, go look atgit-reset(1)instead, especially the--hardoption. and if you want to extract specific files as they were in another commit, that'sgit-restore(1), specifically its--sourceoption. be careful with these alternatives, bestie, because both will discard uncommitted changes in your working directory π
also, for the full breakdown of the differences between the three commands, see "Reset, restore and revert" in git(1) πΈ
π OPTIONS π
<commit>...β the commits you're reverting, periodt. want a more complete list of ways to spell commit names? that'sgitrevisions(7). you can also hand it sets of commits, but no traversal is done by default β seegit-rev-list(1)and its--no-walkoption for that π§-e,--editβ with this one,git revertlets you edit the commit message before committing the revert. this is literally the default when you run the command from a terminal, so it's giving "default behaviour, but make it official" β¨-m parent-number,--mainline parent-numberβ okay so usually you can't revert a merge, because nobody knows which side of the merge should count as the mainline. this option specifies the parent number (starting from1) of the mainline, and lets revert reverse the change relative to that specified parent π reverting a merge commit declares that you will never want the tree changes brought in by that merge. consequence? later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. this may or may not be what you want, so read that twice ngl. see the revert-a-faulty-merge How-To[1] for more details π--no-editβ with this,git revertwill not start the commit message editor. no editor, no waiting, just commit π«Ά--cleanup=<mode>β decides how the commit message gets cleaned up before being passed on to the commit machinery. seegit-commit(1)for the deets. in particular, if<mode>is given the valuescissors, thenscissorswill be appended toMERGE_MSGbefore being passed on in the case of a conflict βοΈ-n,--no-commitβ usually the command automatically creates some commits with commit log messages stating which commits were reverted. this flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. bonus: when you use this option, your index does not have to match theHEADcommit β the revert is done against the beginning state of your index π this is useful when you're reverting more than one commits' effect to your index in a row, iykyk π«-S[<keyid>],--gpg-sign[=<keyid>],--no-gpg-signβ GPG-sign commits π thekeyidargument is optional and defaults to the committer identity; if you specify it, it must be stuck to the option without a space.--no-gpg-signis useful to countermand both thecommit.gpgSignconfiguration variable and earlier--gpg-signβ it's the "nvm, unsigned" button π-s,--signoffβ adds aSigned-off-bytrailer at the end of the commit message. see thesignoffoption ingit-commit(1)for more info ποΈ--strategy=<strategy>β use the given merge strategy. should only be used once. see the MERGE STRATEGIES section ingit-merge(1)for details β-X<option>,--strategy-option=<option>β passes the merge strategy-specific option through to the merge strategy. seegit-merge(1)for details π«--rerere-autoupdate,--no-rerere-autoupdateβ after the rerere mechanism reuses a recorded resolution on the current conflict to update the files in the working tree, this allows it to also update the index with the result of that resolution.--no-rerere-autoupdateis a great way to double-check whatgit-rerere(1)did and catch potential mismerges, before committing the result to the index with a separategit-add(1)π--referenceβ instead of starting the body of the log message withThis reverts <full-object-name-of-the-commit-being-reverted>., it refers to the commit using--pretty=referenceformat (cf.git-log(1)). therevert.referenceconfiguration variable can be used to enable this option by default π
π SEQUENCER SUBCOMMANDS π
these are the "omg something went sideways, what now" commands π«Ά
--continueβ continue the operation in progress using the information in.git/sequencer. can be used to continue after resolving conflicts in a failed cherry-pick or revert πͺ--skipβ skip the current commit and continue with the rest of the sequence. "not this one, next" β¨--quitβ forget about the current operation in progress. can be used to clear the sequencer state after a failed cherry-pick or revert π§Ή--abortβ cancel the operation and return to the pre-sequence state. the "actually, never mind, rewind" button π
π EXAMPLES π
git revert HEAD~3
reverts the changes specified by the fourth last commit in HEAD, and creates a new commit with the reverted changes π (yes, HEAD~3 is the fourth last β git counts from zero-ish, we don't make the rules π₯²)
git revert -n master~5..master~2
reverts the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included), but does not create any commit with the reverted changes. this one only modifies the working tree and the index β very "I'll commit when I'm ready" energy π
π DISCUSSION π
so git does create a basic commit message automatically, but it is strongly recommended that you explain why the original commit is being reverted. future you will thank present you, fr fr π«Ά
also β and this is the funny part β repeatedly reverting reverts will result in increasingly unwieldy subject lines, like, for example:
Reapply "Reapply "<original-subject>""
πππ please consider rewording these to be shorter and more unique. your git log will look so much better for it π
π CONFIGURATION π
everything below this line in this section is selectively included from the git-config(1) documentation, and the content is the same as what's found there π
revert.referenceβ setting this variable totruemakesgit revertbehave as if the--referenceoption is given. one little config, all the vibes β
πΈ SEE ALSO πΈ
git-cherry-pick(1)β its chaotic sibling π¦
π GIT π
part of the git(1) suite, obviously π
π NOTES π
- revert-a-faulty-merge How-To β
file:///usr/share/doc/git-doc/howto/revert-a-faulty-merge.htmlπ
<div align="center">
okay bye bestie, go revert responsibly π
β¨ this page is your bestie-signed, slay-certified rewrite of Git 2.56.0, dated 2026-09-27 β the manual name is GIT-REVERT(1) in case you forgot already πππ¦
</div>
π¦ where this page comes from
- arch rolling: git 2.56.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms