Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 1 | git-revert(1) |
| 2 | ============= |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 3 | |
| 4 | NAME |
| 5 | ---- |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 6 | git-revert - Revert some existing commits |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Martin von Zweigbergk | 7791a1d | 2011-07-01 22:38:26 -0400 | [diff] [blame] | 10 | [verse] |
Jean-Noël Avila | d1ddc4e | 2022-11-26 17:24:02 +0000 | [diff] [blame] | 11 | 'git revert' [--[no-]edit] [-n] [-m <parent-number>] [-s] [-S[<keyid>]] <commit>... |
Rohit Ashiwal | de81ca3 | 2019-07-02 14:41:28 +0530 | [diff] [blame] | 12 | 'git revert' (--continue | --skip | --abort | --quit) |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 13 | |
| 14 | DESCRIPTION |
| 15 | ----------- |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 16 | |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 17 | Given one or more existing commits, revert the changes that the |
| 18 | related patches introduce, and record some new commits that record |
| 19 | them. This requires your working tree to be clean (no modifications |
| 20 | from the HEAD commit). |
| 21 | |
| 22 | Note: 'git revert' is used to record some new commits to reverse the |
| 23 | effect of some earlier commits (often only a faulty one). If you want to |
Tarmigan Casebolt | 3a634dc | 2008-08-19 12:50:31 -0700 | [diff] [blame] | 24 | throw away all uncommitted changes in your working directory, you |
Matthieu Moy | bcf9626 | 2016-06-28 13:40:11 +0200 | [diff] [blame] | 25 | should see linkgit:git-reset[1], particularly the `--hard` option. If |
Tarmigan Casebolt | 3a634dc | 2008-08-19 12:50:31 -0700 | [diff] [blame] | 26 | you want to extract specific files as they were in another commit, you |
Nguyễn Thái Ngọc Duy | 80f537f | 2019-04-25 16:45:58 +0700 | [diff] [blame] | 27 | should see linkgit:git-restore[1], specifically the `--source` |
| 28 | option. Take care with these alternatives as |
Tarmigan Casebolt | 3a634dc | 2008-08-19 12:50:31 -0700 | [diff] [blame] | 29 | both will discard uncommitted changes in your working directory. |
| 30 | |
Nguyễn Thái Ngọc Duy | 46e91b6 | 2019-04-25 16:45:45 +0700 | [diff] [blame] | 31 | See "Reset, restore and revert" in linkgit:git[1] for the differences |
| 32 | between the three commands. |
| 33 | |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 34 | OPTIONS |
| 35 | ------- |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 36 | <commit>...:: |
| 37 | Commits to revert. |
Shawn O. Pearce | 41a5564 | 2007-01-17 21:08:09 -0500 | [diff] [blame] | 38 | For a more complete list of ways to spell commit names, see |
Jonathan Nieder | 9d83e38 | 2010-10-11 11:03:32 -0500 | [diff] [blame] | 39 | linkgit:gitrevisions[7]. |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 40 | Sets of commits can also be given but no traversal is done by |
Matthieu Moy | bcf9626 | 2016-06-28 13:40:11 +0200 | [diff] [blame] | 41 | default, see linkgit:git-rev-list[1] and its `--no-walk` |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 42 | option. |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 43 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 44 | -e:: |
| 45 | --edit:: |
Thomas Rast | 0b444cd | 2010-01-10 00:33:00 +0100 | [diff] [blame] | 46 | With this option, 'git revert' will let you edit the commit |
Jim Meyering | 233808d | 2008-01-19 16:23:32 +0100 | [diff] [blame] | 47 | message prior to committing the revert. This is the default if |
Petr Baudis | 8bf14d6 | 2005-11-26 23:12:44 +0100 | [diff] [blame] | 48 | you run the command from a terminal. |
| 49 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 50 | -m parent-number:: |
| 51 | --mainline parent-number:: |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 52 | 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 Jr | b80b5d6 | 2008-12-21 18:26:03 -0600 | [diff] [blame] | 57 | + |
| 58 | Reverting a merge commit declares that you will never want the tree changes |
| 59 | brought in by the merge. As a result, later merges will only bring in tree |
| 60 | changes introduced by commits that are not ancestors of the previously |
| 61 | reverted merge. This may or may not be what you want. |
| 62 | + |
Sebastian Schuberth | d5ff3b4 | 2013-09-06 22:03:22 +0200 | [diff] [blame] | 63 | See the link:howto/revert-a-faulty-merge.html[revert-a-faulty-merge How-To] for |
Boyd Stephen Smith Jr | b80b5d6 | 2008-12-21 18:26:03 -0600 | [diff] [blame] | 64 | more details. |
Junio C Hamano | 7791ecb | 2007-10-23 13:33:26 -0700 | [diff] [blame] | 65 | |
Petr Baudis | 8bf14d6 | 2005-11-26 23:12:44 +0100 | [diff] [blame] | 66 | --no-edit:: |
Thomas Rast | 0b444cd | 2010-01-10 00:33:00 +0100 | [diff] [blame] | 67 | With this option, 'git revert' will not start the commit |
Petr Baudis | 8bf14d6 | 2005-11-26 23:12:44 +0100 | [diff] [blame] | 68 | message editor. |
| 69 | |
Denton Liu | 1a2b985 | 2019-04-17 11:23:30 +0100 | [diff] [blame] | 70 | --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 Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 77 | -n:: |
| 78 | --no-commit:: |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 79 | 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 Baudis | 8bd867e | 2008-07-16 14:35:22 +0200 | [diff] [blame] | 84 | 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 Fonseca | df8baa4 | 2005-10-03 19:16:30 +0200 | [diff] [blame] | 87 | + |
| 88 | This is useful when reverting more than one commits' |
Petr Baudis | 8bd867e | 2008-07-16 14:35:22 +0200 | [diff] [blame] | 89 | effect to your index in a row. |
Junio C Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 90 | |
Matthieu Moy | 340f2c5 | 2015-09-19 09:47:48 +0200 | [diff] [blame] | 91 | -S[<keyid>]:: |
| 92 | --gpg-sign[=<keyid>]:: |
Đoàn Trần Công Danh | cf0ad4d | 2020-04-03 17:28:03 +0700 | [diff] [blame] | 93 | --no-gpg-sign:: |
Matthieu Moy | 2b594bf | 2015-09-19 09:47:50 +0200 | [diff] [blame] | 94 | 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 Danh | cf0ad4d | 2020-04-03 17:28:03 +0700 | [diff] [blame] | 96 | 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 Vigier | 3253553 | 2014-01-24 00:50:58 +0000 | [diff] [blame] | 99 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 100 | -s:: |
| 101 | --signoff:: |
Bradley M. Kuhn | 3abd4a6 | 2020-10-19 18:03:55 -0700 | [diff] [blame] | 102 | Add a `Signed-off-by` trailer at the end of the commit message. |
David A. Wheeler | b2c150d | 2016-01-05 14:20:26 -0500 | [diff] [blame] | 103 | See the signoff option in linkgit:git-commit[1] for more information. |
Dan McGee | cfd9c27 | 2008-04-26 15:14:28 -0500 | [diff] [blame] | 104 | |
Jonathan Nieder | 67ac1e1 | 2010-12-10 18:51:44 -0600 | [diff] [blame] | 105 | --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 Hamano | 0dbc715 | 2022-07-15 14:32:18 -0700 | [diff] [blame] | 115 | include::rerere-options.txt[] |
Phillip Wood | aba4954 | 2019-03-14 19:12:32 +0000 | [diff] [blame] | 116 | |
Junio C Hamano | 43966ab | 2022-05-26 23:01:39 -0700 | [diff] [blame] | 117 | --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 Ramachandra | 26ae337 | 2011-08-04 16:09:11 +0530 | [diff] [blame] | 126 | SEQUENCER SUBCOMMANDS |
| 127 | --------------------- |
| 128 | include::sequencer.txt[] |
| 129 | |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 130 | EXAMPLES |
| 131 | -------- |
Jeff King | 5d2fc91 | 2011-08-03 20:13:29 -0600 | [diff] [blame] | 132 | `git revert HEAD~3`:: |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 133 | |
| 134 | Revert the changes specified by the fourth last commit in HEAD |
| 135 | and create a new commit with the reverted changes. |
| 136 | |
Jeff King | 6cf378f | 2012-04-26 04:51:57 -0400 | [diff] [blame] | 137 | `git revert -n master~5..master~2`:: |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 138 | |
| 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 Hamano | de2b82c | 2005-08-28 03:01:09 -0700 | [diff] [blame] | 144 | |
Ævar Arnfjörð Bjarmason | 16f6b0d | 2022-09-07 10:27:04 +0200 | [diff] [blame] | 145 | CONFIGURATION |
| 146 | ------------- |
| 147 | |
| 148 | include::includes/cmd-config-section-all.txt[] |
| 149 | |
| 150 | include::config/revert.txt[] |
| 151 | |
Christian Couder | 86c7bb4 | 2010-06-02 07:58:41 +0200 | [diff] [blame] | 152 | SEE ALSO |
| 153 | -------- |
| 154 | linkgit:git-cherry-pick[1] |
| 155 | |
Junio C Hamano | 7fc9d69 | 2005-08-23 01:49:47 -0700 | [diff] [blame] | 156 | GIT |
| 157 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 158 | Part of the linkgit:git[1] suite |