summaryrefslogtreecommitdiffstats
path: root/man1/git-revert.1
blob: a52fbdf11921b278cca1591429558f47ac375e9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
'\" t
.\"     Title: git-revert
.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\"      Date: 2024-04-12
.\"    Manual: Git Manual
.\"    Source: Git 2.44.0.591.g8f7582d995
.\"  Language: English
.\"
.TH "GIT\-REVERT" "1" "2024\-04\-12" "Git 2\&.44\&.0\&.591\&.g8f7582" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
git-revert \- Revert some existing commits
.SH "SYNOPSIS"
.sp
.nf
\fIgit revert\fR [\-\-[no\-]edit] [\-n] [\-m <parent\-number>] [\-s] [\-S[<keyid>]] <commit>\&...
\fIgit revert\fR (\-\-continue | \-\-skip | \-\-abort | \-\-quit)
.fi
.sp
.SH "DESCRIPTION"
.sp
Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them\&. This requires your working tree to be clean (no modifications from the HEAD commit)\&.
.sp
Note: \fIgit revert\fR is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one)\&. If you want to throw away all uncommitted changes in your working directory, you should see \fBgit-reset\fR(1), particularly the \fB\-\-hard\fR option\&. If you want to extract specific files as they were in another commit, you should see \fBgit-restore\fR(1), specifically the \fB\-\-source\fR option\&. Take care with these alternatives as both will discard uncommitted changes in your working directory\&.
.sp
See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
.SH "OPTIONS"
.PP
<commit>\&...
.RS 4
Commits to revert\&. For a more complete list of ways to spell commit names, see
\fBgitrevisions\fR(7)\&. Sets of commits can also be given but no traversal is done by default, see
\fBgit-rev-list\fR(1)
and its
\fB\-\-no\-walk\fR
option\&.
.RE
.PP
\-e, \-\-edit
.RS 4
With this option,
\fIgit revert\fR
will let you edit the commit message prior to committing the revert\&. This is the default if you run the command from a terminal\&.
.RE
.PP
\-m parent\-number, \-\-mainline parent\-number
.RS 4
Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline\&. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent\&.
.sp
Reverting a merge commit declares that you will never want the tree changes brought in by the merge\&. As a result, 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\&.
.sp
See the
\m[blue]\fBrevert\-a\-faulty\-merge How\-To\fR\m[]\&\s-2\u[1]\d\s+2
for more details\&.
.RE
.PP
\-\-no\-edit
.RS 4
With this option,
\fIgit revert\fR
will not start the commit message editor\&.
.RE
.PP
\-\-cleanup=<mode>
.RS 4
This option determines how the commit message will be cleaned up before being passed on to the commit machinery\&. See
\fBgit-commit\fR(1)
for more details\&. In particular, if the
\fI<mode>\fR
is given a value of
\fBscissors\fR, scissors will be appended to
\fBMERGE_MSG\fR
before being passed on in the case of a conflict\&.
.RE
.PP
\-n, \-\-no\-commit
.RS 4
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\&. In addition, when this option is used, your index does not have to match the HEAD commit\&. The revert is done against the beginning state of your index\&.
.sp
This is useful when reverting more than one commits\*(Aq effect to your index in a row\&.
.RE
.PP
\-S[<keyid>], \-\-gpg\-sign[=<keyid>], \-\-no\-gpg\-sign
.RS 4
GPG\-sign commits\&. The
\fBkeyid\fR
argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space\&.
\fB\-\-no\-gpg\-sign\fR
is useful to countermand both
\fBcommit\&.gpgSign\fR
configuration variable, and earlier
\fB\-\-gpg\-sign\fR\&.
.RE
.PP
\-s, \-\-signoff
.RS 4
Add a
\fBSigned\-off\-by\fR
trailer at the end of the commit message\&. See the signoff option in
\fBgit-commit\fR(1)
for more information\&.
.RE
.PP
\-\-strategy=<strategy>
.RS 4
Use the given merge strategy\&. Should only be used once\&. See the MERGE STRATEGIES section in
\fBgit-merge\fR(1)
for details\&.
.RE
.PP
\-X<option>, \-\-strategy\-option=<option>
.RS 4
Pass the merge strategy\-specific option through to the merge strategy\&. See
\fBgit-merge\fR(1)
for details\&.
.RE
.PP
\-\-rerere\-autoupdate, \-\-no\-rerere\-autoupdate
.RS 4
After the rerere mechanism reuses a recorded resolution on the current conflict to update the files in the working tree, allow it to also update the index with the result of resolution\&.
\fB\-\-no\-rerere\-autoupdate\fR
is a good way to double\-check what
\fBrerere\fR
did and catch potential mismerges, before committing the result to the index with a separate
\fBgit add\fR\&.
.RE
.PP
\-\-reference
.RS 4
Instead of starting the body of the log message with "This reverts <full\-object\-name\-of\-the\-commit\-being\-reverted>\&.", refer to the commit using "\-\-pretty=reference" format (cf\&.
\fBgit-log\fR(1))\&. The
\fBrevert\&.reference\fR
configuration variable can be used to enable this option by default\&.
.RE
.SH "SEQUENCER SUBCOMMANDS"
.PP
\-\-continue
.RS 4
Continue the operation in progress using the information in
\fB\&.git/sequencer\fR\&. Can be used to continue after resolving conflicts in a failed cherry\-pick or revert\&.
.RE
.PP
\-\-skip
.RS 4
Skip the current commit and continue with the rest of the sequence\&.
.RE
.PP
\-\-quit
.RS 4
Forget about the current operation in progress\&. Can be used to clear the sequencer state after a failed cherry\-pick or revert\&.
.RE
.PP
\-\-abort
.RS 4
Cancel the operation and return to the pre\-sequence state\&.
.RE
.SH "EXAMPLES"
.PP
\fBgit revert HEAD~3\fR
.RS 4
Revert the changes specified by the fourth last commit in HEAD and create a new commit with the reverted changes\&.
.RE
.PP
\fBgit revert \-n master~5\&.\&.master~2\fR
.RS 4
Revert the changes done by commits from the fifth last commit in master (included) to the third last commit in master (included), but do not create any commit with the reverted changes\&. The revert only modifies the working tree and the index\&.
.RE
.SH "DISCUSSION"
.sp
While git creates a basic commit message automatically, it is \fIstrongly\fR recommended to explain why the original commit is being reverted\&. In addition, repeatedly reverting reverts will result in increasingly unwieldy subject lines, for example \fIReapply "Reapply "<original\-subject>""\fR\&. Please consider rewording these to be shorter and more unique\&.
.SH "CONFIGURATION"
.sp
Everything below this line in this section is selectively included from the \fBgit-config\fR(1) documentation\&. The content is the same as what\(cqs found there:
.PP
revert\&.reference
.RS 4
Setting this variable to true makes
\fBgit revert\fR
behave as if the
\fB\-\-reference\fR
option is given\&.
.RE
.SH "SEE ALSO"
.sp
\fBgit-cherry-pick\fR(1)
.SH "GIT"
.sp
Part of the \fBgit\fR(1) suite
.SH "NOTES"
.IP " 1." 4
revert-a-faulty-merge How-To
.RS 4
\%git-htmldocs/howto/revert-a-faulty-merge.html
.RE