NAME

git-revert - Revert some existing commits

SYNOPSIS

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

DESCRIPTION

Given one or more existing commits, revert the changes that therelated patches introduce, and record some new commits that recordthem. This requires your working tree to be clean (no modificationsfrom the HEAD commit).

Note: git revert is used to record some new commits to reverse theeffect of some earlier commits (often only a faulty one). If you want tothrow away all uncommitted changes in your working directory, youshould see git-reset[1], particularly the —hard option. Ifyou want to extract specific files as they were in another commit, youshould see git-restore[1], specifically the —sourceoption. Take care with these alternatives asboth will discard uncommitted changes in your working directory.

See "Reset, restore and revert" in git[1] for the differencesbetween the three commands.

OPTIONS

  • …​
  • Commits to revert.For a more complete list of ways to spell commit names, seegitrevisions[7].Sets of commits can also be given but no traversal is done bydefault, see git-rev-list[1] and its —no-walkoption.

  • -e

  • —edit
  • With this option, git revert will let you edit the commitmessage prior to committing the revert. This is the default ifyou run the command from a terminal.

  • -m parent-number

  • —mainline parent-number
  • Usually you cannot revert a merge because you do not know whichside of the merge should be considered the mainline. Thisoption specifies the parent number (starting from 1) ofthe mainline and allows revert to reverse the changerelative to the specified parent.

Reverting a merge commit declares that you will never want the tree changesbrought in by the merge. As a result, later merges will only bring in treechanges introduced by commits that are not ancestors of the previouslyreverted merge. This may or may not be what you want.

See the revert-a-faulty-merge How-To formore details.

  • —no-edit
  • With this option, git revert will not start the commitmessage editor.

  • —cleanup=

  • This option determines how the commit message will be cleaned up beforebeing passed on to the commit machinery. See git-commit[1] for moredetails. In particular, if the is given a value of scissors,scissors will be appended to MERGE_MSG before being passed on in the caseof a conflict.

  • -n

  • —no-commit
  • Usually the command automatically creates some commits withcommit log messages stating which commits werereverted. This flag applies the changes necessaryto revert the named commits to your working treeand the index, but does not make the commits. In addition,when this option is used, your index does not have to matchthe HEAD commit. The revert is done against thebeginning state of your index.

This is useful when reverting more than one commits'effect to your index in a row.

  • -S[]
  • —gpg-sign[=]
  • GPG-sign commits. The keyid argument is optional anddefaults to the committer identity; if specified, it must bestuck to the option without a space.

  • -s

  • —signoff
  • Add Signed-off-by line at the end of the commit message.See the signoff option in git-commit[1] for more information.

  • —strategy=

  • Use the given merge strategy. Should only be used once.See the MERGE STRATEGIES section in git-merge[1]for details.

  • -X

  • —strategy-option=
  • Pass the merge strategy-specific option through to themerge strategy. See git-merge[1] for details.

  • —rerere-autoupdate

  • —no-rerere-autoupdate
  • Allow the rerere mechanism to update the index with theresult of auto-conflict resolution if possible.

SEQUENCER SUBCOMMANDS

  • —continue
  • Continue the operation in progress using the information in.git/sequencer. Can be used to continue after resolvingconflicts in a failed cherry-pick or revert.

  • —skip

  • Skip the current commit and continue with the rest of thesequence.

  • —quit

  • Forget about the current operation in progress. Can be usedto clear the sequencer state after a failed cherry-pick orrevert.

  • —abort

  • Cancel the operation and return to the pre-sequence state.

EXAMPLES

  • git revert HEAD~3
  • Revert the changes specified by the fourth last commit in HEADand create a new commit with the reverted changes.

  • git revert -n master~5..master~2

  • Revert the changes done by commits from the fifth last commitin master (included) to the third last commit in master(included), but do not create any commit with the revertedchanges. The revert only modifies the working tree and theindex.

SEE ALSO

git-cherry-pick[1]

GIT

Part of the git[1] suite