doc: promote "git restore"
[git.git] / Documentation / git-revert.txt
blob9aadc36881beae56b11202450947bcf28f94f3f6
1 git-revert(1)
2 =============
4 NAME
5 ----
6 git-revert - Revert some existing commits
8 SYNOPSIS
9 --------
10 [verse]
11 'git revert' [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>...
12 'git revert' --continue
13 'git revert' --quit
14 'git revert' --abort
16 DESCRIPTION
17 -----------
19 Given one or more existing commits, revert the changes that the
20 related patches introduce, and record some new commits that record
21 them.  This requires your working tree to be clean (no modifications
22 from the HEAD commit).
24 Note: 'git revert' is used to record some new commits to reverse the
25 effect of some earlier commits (often only a faulty one).  If you want to
26 throw away all uncommitted changes in your working directory, you
27 should see linkgit:git-reset[1], particularly the `--hard` option.  If
28 you want to extract specific files as they were in another commit, you
29 should see linkgit:git-restore[1], specifically the `--source`
30 option. Take care with these alternatives as
31 both will discard uncommitted changes in your working directory.
33 See "Reset, restore and revert" in linkgit:git[1] for the differences
34 between the three commands.
36 OPTIONS
37 -------
38 <commit>...::
39         Commits to revert.
40         For a more complete list of ways to spell commit names, see
41         linkgit:gitrevisions[7].
42         Sets of commits can also be given but no traversal is done by
43         default, see linkgit:git-rev-list[1] and its `--no-walk`
44         option.
46 -e::
47 --edit::
48         With this option, 'git revert' will let you edit the commit
49         message prior to committing the revert. This is the default if
50         you run the command from a terminal.
52 -m parent-number::
53 --mainline parent-number::
54         Usually you cannot revert a merge because you do not know which
55         side of the merge should be considered the mainline.  This
56         option specifies the parent number (starting from 1) of
57         the mainline and allows revert to reverse the change
58         relative to the specified parent.
60 Reverting a merge commit declares that you will never want the tree changes
61 brought in by the merge.  As a result, later merges will only bring in tree
62 changes introduced by commits that are not ancestors of the previously
63 reverted merge.  This may or may not be what you want.
65 See the link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for
66 more details.
68 --no-edit::
69         With this option, 'git revert' will not start the commit
70         message editor.
72 -n::
73 --no-commit::
74         Usually the command automatically creates some commits with
75         commit log messages stating which commits were
76         reverted.  This flag applies the changes necessary
77         to revert the named commits to your working tree
78         and the index, but does not make the commits.  In addition,
79         when this option is used, your index does not have to match
80         the HEAD commit.  The revert is done against the
81         beginning state of your index.
83 This is useful when reverting more than one commits'
84 effect to your index in a row.
86 -S[<keyid>]::
87 --gpg-sign[=<keyid>]::
88         GPG-sign commits. The `keyid` argument is optional and
89         defaults to the committer identity; if specified, it must be
90         stuck to the option without a space.
92 -s::
93 --signoff::
94         Add Signed-off-by line at the end of the commit message.
95         See the signoff option in linkgit:git-commit[1] for more information.
97 --strategy=<strategy>::
98         Use the given merge strategy.  Should only be used once.
99         See the MERGE STRATEGIES section in linkgit:git-merge[1]
100         for details.
102 -X<option>::
103 --strategy-option=<option>::
104         Pass the merge strategy-specific option through to the
105         merge strategy.  See linkgit:git-merge[1] for details.
107 SEQUENCER SUBCOMMANDS
108 ---------------------
109 include::sequencer.txt[]
111 EXAMPLES
112 --------
113 `git revert HEAD~3`::
115         Revert the changes specified by the fourth last commit in HEAD
116         and create a new commit with the reverted changes.
118 `git revert -n master~5..master~2`::
120         Revert the changes done by commits from the fifth last commit
121         in master (included) to the third last commit in master
122         (included), but do not create any commit with the reverted
123         changes. The revert only modifies the working tree and the
124         index.
126 SEE ALSO
127 --------
128 linkgit:git-cherry-pick[1]
132 Part of the linkgit:git[1] suite