1GIT-REVERT(1) Git Manual GIT-REVERT(1)
2
3
4
6 git-revert - Revert some existing commits
7
9 git revert [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>...
10 git revert (--continue | --skip | --abort | --quit)
11
13 Given one or more existing commits, revert the changes that the related
14 patches introduce, and record some new commits that record them. This
15 requires your working tree to be clean (no modifications from the HEAD
16 commit).
17
18 Note: git revert is used to record some new commits to reverse the
19 effect of some earlier commits (often only a faulty one). If you want
20 to throw away all uncommitted changes in your working directory, you
21 should see git-reset(1), particularly the --hard option. If you want to
22 extract specific files as they were in another commit, you should see
23 git-restore(1), specifically the --source option. Take care with these
24 alternatives as both will discard uncommitted changes in your working
25 directory.
26
27 See "Reset, restore and revert" in git(1) for the differences between
28 the three commands.
29
31 <commit>...
32 Commits to revert. For a more complete list of ways to spell commit
33 names, see gitrevisions(7). Sets of commits can also be given but
34 no traversal is done by default, see git-rev-list(1) and its
35 --no-walk option.
36
37 -e, --edit
38 With this option, git revert will let you edit the commit message
39 prior to committing the revert. This is the default if you run the
40 command from a terminal.
41
42 -m parent-number, --mainline parent-number
43 Usually you cannot revert a merge because you do not know which
44 side of the merge should be considered the mainline. This option
45 specifies the parent number (starting from 1) of the mainline and
46 allows revert to reverse the change relative to the specified
47 parent.
48
49 Reverting a merge commit declares that you will never want the tree
50 changes brought in by the merge. As a result, later merges will
51 only bring in tree changes introduced by commits that are not
52 ancestors of the previously reverted merge. This may or may not be
53 what you want.
54
55 See the revert-a-faulty-merge How-To[1] for more details.
56
57 --no-edit
58 With this option, git revert will not start the commit message
59 editor.
60
61 --cleanup=<mode>
62 This option determines how the commit message will be cleaned up
63 before being passed on to the commit machinery. See git-commit(1)
64 for more details. In particular, if the <mode> is given a value of
65 scissors, scissors will be appended to MERGE_MSG before being
66 passed on in the case of a conflict.
67
68 -n, --no-commit
69 Usually the command automatically creates some commits with commit
70 log messages stating which commits were reverted. This flag applies
71 the changes necessary to revert the named commits to your working
72 tree and the index, but does not make the commits. In addition,
73 when this option is used, your index does not have to match the
74 HEAD commit. The revert is done against the beginning state of your
75 index.
76
77 This is useful when reverting more than one commits' effect to your
78 index in a row.
79
80 -S[<keyid>], --gpg-sign[=<keyid>], --no-gpg-sign
81 GPG-sign commits. The keyid argument is optional and defaults to
82 the committer identity; if specified, it must be stuck to the
83 option without a space. --no-gpg-sign is useful to countermand
84 both commit.gpgSign configuration variable, and earlier --gpg-sign.
85
86 -s, --signoff
87 Add a Signed-off-by trailer at the end of the commit message. See
88 the signoff option in git-commit(1) for more information.
89
90 --strategy=<strategy>
91 Use the given merge strategy. Should only be used once. See the
92 MERGE STRATEGIES section in git-merge(1) for details.
93
94 -X<option>, --strategy-option=<option>
95 Pass the merge strategy-specific option through to the merge
96 strategy. See git-merge(1) for details.
97
98 --rerere-autoupdate, --no-rerere-autoupdate
99 After the rerere mechanism reuses a recorded resolution on the
100 current conflict to update the files in the working tree, allow it
101 to also update the index with the result of resolution.
102 --no-rerere-autoupdate is a good way to double-check what rerere
103 did and catch potential mismerges, before committing the result to
104 the index with a separate git add.
105
106 --reference
107 Instead of starting the body of the log message with "This reverts
108 <full object name of the commit being reverted>.", refer to the
109 commit using "--pretty=reference" format (cf. git-log(1)). The
110 revert.reference configuration variable can be used to enable this
111 option by default.
112
114 --continue
115 Continue the operation in progress using the information in
116 .git/sequencer. Can be used to continue after resolving conflicts
117 in a failed cherry-pick or revert.
118
119 --skip
120 Skip the current commit and continue with the rest of the sequence.
121
122 --quit
123 Forget about the current operation in progress. Can be used to
124 clear the sequencer state after a failed cherry-pick or revert.
125
126 --abort
127 Cancel the operation and return to the pre-sequence state.
128
130 git revert HEAD~3
131 Revert the changes specified by the fourth last commit in HEAD and
132 create a new commit with the reverted changes.
133
134 git revert -n master~5..master~2
135 Revert the changes done by commits from the fifth last commit in
136 master (included) to the third last commit in master (included),
137 but do not create any commit with the reverted changes. The revert
138 only modifies the working tree and the index.
139
141 While git creates a basic commit message automatically, it is strongly
142 recommended to explain why the original commit is being reverted. In
143 addition, repeatedly reverting reverts will result in increasingly
144 unwieldy subject lines, for example Reapply "Reapply "<original
145 subject>"". Please consider rewording these to be shorter and more
146 unique.
147
149 Everything below this line in this section is selectively included from
150 the git-config(1) documentation. The content is the same as what’s
151 found there:
152
153 revert.reference
154 Setting this variable to true makes git revert behave as if the
155 --reference option is given.
156
158 git-cherry-pick(1)
159
161 Part of the git(1) suite
162
164 1. revert-a-faulty-merge How-To
165 file:///usr/share/doc/git/howto/revert-a-faulty-merge.html
166
167
168
169Git 2.43.0 11/20/2023 GIT-REVERT(1)