blob: d2e10d3dceb60e0a6c8322a47f8017701338710e [file] [log] [blame]
Junio C Hamano215a7ad2005-09-07 17:26:23 -07001git-revert(1)
2=============
Junio C Hamano7fc9d692005-08-23 01:49:47 -07003
4NAME
5----
Christian Couder86c7bb42010-06-02 07:58:41 +02006git-revert - Revert some existing commits
Junio C Hamano7fc9d692005-08-23 01:49:47 -07007
8SYNOPSIS
9--------
Martin von Zweigbergk7791a1d2011-07-01 22:38:26 -040010[verse]
Jean-Noël Avilad1ddc4e2022-11-26 17:24:02 +000011'git revert' [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>...
Rohit Ashiwalde81ca32019-07-02 14:41:28 +053012'git revert' (--continue | --skip | --abort | --quit)
Junio C Hamano7fc9d692005-08-23 01:49:47 -070013
14DESCRIPTION
15-----------
Junio C Hamano7fc9d692005-08-23 01:49:47 -070016
Christian Couder86c7bb42010-06-02 07:58:41 +020017Given one or more existing commits, revert the changes that the
18related patches introduce, and record some new commits that record
19them. This requires your working tree to be clean (no modifications
20from the HEAD commit).
21
22Note: 'git revert' is used to record some new commits to reverse the
23effect of some earlier commits (often only a faulty one). If you want to
Tarmigan Casebolt3a634dc2008-08-19 12:50:31 -070024throw away all uncommitted changes in your working directory, you
Matthieu Moybcf96262016-06-28 13:40:11 +020025should see linkgit:git-reset[1], particularly the `--hard` option. If
Tarmigan Casebolt3a634dc2008-08-19 12:50:31 -070026you want to extract specific files as they were in another commit, you
Nguyễn Thái Ngọc Duy80f537f2019-04-25 16:45:58 +070027should see linkgit:git-restore[1], specifically the `--source`
28option. Take care with these alternatives as
Tarmigan Casebolt3a634dc2008-08-19 12:50:31 -070029both will discard uncommitted changes in your working directory.
30
Nguyễn Thái Ngọc Duy46e91b62019-04-25 16:45:45 +070031See "Reset, restore and revert" in linkgit:git[1] for the differences
32between the three commands.
33
Junio C Hamano7fc9d692005-08-23 01:49:47 -070034OPTIONS
35-------
Christian Couder86c7bb42010-06-02 07:58:41 +020036<commit>...::
37 Commits to revert.
Shawn O. Pearce41a55642007-01-17 21:08:09 -050038 For a more complete list of ways to spell commit names, see
Jonathan Nieder9d83e382010-10-11 11:03:32 -050039 linkgit:gitrevisions[7].
Christian Couder86c7bb42010-06-02 07:58:41 +020040 Sets of commits can also be given but no traversal is done by
Matthieu Moybcf96262016-06-28 13:40:11 +020041 default, see linkgit:git-rev-list[1] and its `--no-walk`
Christian Couder86c7bb42010-06-02 07:58:41 +020042 option.
Junio C Hamano7fc9d692005-08-23 01:49:47 -070043
Stephan Beyer32402402008-06-08 03:36:09 +020044-e::
45--edit::
Thomas Rast0b444cd2010-01-10 00:33:00 +010046 With this option, 'git revert' will let you edit the commit
Jim Meyering233808d2008-01-19 16:23:32 +010047 message prior to committing the revert. This is the default if
Petr Baudis8bf14d62005-11-26 23:12:44 +010048 you run the command from a terminal.
49
Stephan Beyer32402402008-06-08 03:36:09 +020050-m parent-number::
51--mainline parent-number::
Junio C Hamano7791ecb2007-10-23 13:33:26 -070052 Usually you cannot revert a merge because you do not know which
53 side of the merge should be considered the mainline. This
54 option specifies the parent number (starting from 1) of
55 the mainline and allows revert to reverse the change
56 relative to the specified parent.
Boyd Stephen Smith Jrb80b5d62008-12-21 18:26:03 -060057+
58Reverting a merge commit declares that you will never want the tree changes
59brought in by the merge. As a result, later merges will only bring in tree
60changes introduced by commits that are not ancestors of the previously
61reverted merge. This may or may not be what you want.
62+
Sebastian Schuberthd5ff3b42013-09-06 22:03:22 +020063See the link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for
Boyd Stephen Smith Jrb80b5d62008-12-21 18:26:03 -060064more details.
Junio C Hamano7791ecb2007-10-23 13:33:26 -070065
Petr Baudis8bf14d62005-11-26 23:12:44 +010066--no-edit::
Thomas Rast0b444cd2010-01-10 00:33:00 +010067 With this option, 'git revert' will not start the commit
Petr Baudis8bf14d62005-11-26 23:12:44 +010068 message editor.
69
Denton Liu1a2b9852019-04-17 11:23:30 +010070--cleanup=<mode>::
71 This option determines how the commit message will be cleaned up before
72 being passed on to the commit machinery. See linkgit:git-commit[1] for more
73 details. In particular, if the '<mode>' is given a value of `scissors`,
74 scissors will be appended to `MERGE_MSG` before being passed on in the case
75 of a conflict.
76
Stephan Beyer32402402008-06-08 03:36:09 +020077-n::
78--no-commit::
Christian Couder86c7bb42010-06-02 07:58:41 +020079 Usually the command automatically creates some commits with
80 commit log messages stating which commits were
81 reverted. This flag applies the changes necessary
82 to revert the named commits to your working tree
83 and the index, but does not make the commits. In addition,
Petr Baudis8bd867e2008-07-16 14:35:22 +020084 when this option is used, your index does not have to match
85 the HEAD commit. The revert is done against the
86 beginning state of your index.
Jonas Fonsecadf8baa42005-10-03 19:16:30 +020087+
88This is useful when reverting more than one commits'
Petr Baudis8bd867e2008-07-16 14:35:22 +020089effect to your index in a row.
Junio C Hamanode2b82c2005-08-28 03:01:09 -070090
Matthieu Moy340f2c52015-09-19 09:47:48 +020091-S[<keyid>]::
92--gpg-sign[=<keyid>]::
Đoàn Trần Công Danhcf0ad4d2020-04-03 17:28:03 +070093--no-gpg-sign::
Matthieu Moy2b594bf2015-09-19 09:47:50 +020094 GPG-sign commits. The `keyid` argument is optional and
95 defaults to the committer identity; if specified, it must be
Đoàn Trần Công Danhcf0ad4d2020-04-03 17:28:03 +070096 stuck to the option without a space. `--no-gpg-sign` is useful to
97 countermand both `commit.gpgSign` configuration variable, and
98 earlier `--gpg-sign`.
Nicolas Vigier32535532014-01-24 00:50:58 +000099
Stephan Beyer32402402008-06-08 03:36:09 +0200100-s::
101--signoff::
Bradley M. Kuhn3abd4a62020-10-19 18:03:55 -0700102 Add a `Signed-off-by` trailer at the end of the commit message.
David A. Wheelerb2c150d2016-01-05 14:20:26 -0500103 See the signoff option in linkgit:git-commit[1] for more information.
Dan McGeecfd9c272008-04-26 15:14:28 -0500104
Jonathan Nieder67ac1e12010-12-10 18:51:44 -0600105--strategy=<strategy>::
106 Use the given merge strategy. Should only be used once.
107 See the MERGE STRATEGIES section in linkgit:git-merge[1]
108 for details.
109
110-X<option>::
111--strategy-option=<option>::
112 Pass the merge strategy-specific option through to the
113 merge strategy. See linkgit:git-merge[1] for details.
114
Junio C Hamano0dbc7152022-07-15 14:32:18 -0700115include::rerere-options.txt[]
Phillip Woodaba49542019-03-14 19:12:32 +0000116
Junio C Hamano43966ab2022-05-26 23:01:39 -0700117--reference::
118 Instead of starting the body of the log message with "This
119 reverts <full object name of the commit being reverted>.",
120 refer to the commit using "--pretty=reference" format
121 (cf. linkgit:git-log[1]). The `revert.reference`
122 configuration variable can be used to enable this option by
123 default.
124
125
Ramkumar Ramachandra26ae3372011-08-04 16:09:11 +0530126SEQUENCER SUBCOMMANDS
127---------------------
128include::sequencer.txt[]
129
Christian Couder86c7bb42010-06-02 07:58:41 +0200130EXAMPLES
131--------
Jeff King5d2fc912011-08-03 20:13:29 -0600132`git revert HEAD~3`::
Christian Couder86c7bb42010-06-02 07:58:41 +0200133
134 Revert the changes specified by the fourth last commit in HEAD
135 and create a new commit with the reverted changes.
136
Jeff King6cf378f2012-04-26 04:51:57 -0400137`git revert -n master~5..master~2`::
Christian Couder86c7bb42010-06-02 07:58:41 +0200138
139 Revert the changes done by commits from the fifth last commit
140 in master (included) to the third last commit in master
141 (included), but do not create any commit with the reverted
142 changes. The revert only modifies the working tree and the
143 index.
Junio C Hamanode2b82c2005-08-28 03:01:09 -0700144
Ævar Arnfjörð Bjarmason16f6b0d2022-09-07 10:27:04 +0200145CONFIGURATION
146-------------
147
148include::includes/cmd-config-section-all.txt[]
149
150include::config/revert.txt[]
151
Christian Couder86c7bb42010-06-02 07:58:41 +0200152SEE ALSO
153--------
154linkgit:git-cherry-pick[1]
155
Junio C Hamano7fc9d692005-08-23 01:49:47 -0700156GIT
157---
Christian Couder9e1f0a82008-06-06 09:07:32 +0200158Part of the linkgit:git[1] suite