Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-revert(1) |
| 2 | ============= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 6 | git-revert - Revert some existing commits |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 10 | [verse] |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 11 | 'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>... |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 12 | 'git revert' --continue |
Junio C Hamano | f0944d0 | 2011-11-30 20:46:29 | [diff] [blame] | 13 | 'git revert' --quit |
| 14 | 'git revert' --abort |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
| 16 | DESCRIPTION |
| 17 | ----------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 18 | |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 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). |
| 23 | |
| 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 |
Junio C Hamano | 3580ad2 | 2008-08-21 00:27:40 | [diff] [blame] | 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 |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 29 | should see linkgit:git-checkout[1], specifically the `git checkout |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 30 | <commit> -- <filename>` syntax. Take care with these alternatives as |
Junio C Hamano | 3580ad2 | 2008-08-21 00:27:40 | [diff] [blame] | 31 | both will discard uncommitted changes in your working directory. |
| 32 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 33 | OPTIONS |
| 34 | ------- |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 35 | <commit>...:: |
| 36 | Commits to revert. |
Junio C Hamano | 2d47c62 | 2007-01-18 06:24:10 | [diff] [blame] | 37 | For a more complete list of ways to spell commit names, see |
Junio C Hamano | c27b733 | 2010-10-14 04:37:28 | [diff] [blame] | 38 | linkgit:gitrevisions[7]. |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 39 | Sets of commits can also be given but no traversal is done by |
| 40 | default, see linkgit:git-rev-list[1] and its '--no-walk' |
| 41 | option. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 42 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 43 | -e:: |
| 44 | --edit:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 45 | With this option, 'git revert' will let you edit the commit |
Junio C Hamano | 0e66113 | 2008-01-21 02:37:44 | [diff] [blame] | 46 | message prior to committing the revert. This is the default if |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 47 | you run the command from a terminal. |
| 48 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 49 | -m parent-number:: |
| 50 | --mainline parent-number:: |
Junio C Hamano | d814b6d | 2007-11-04 11:13:49 | [diff] [blame] | 51 | Usually you cannot revert a merge because you do not know which |
| 52 | side of the merge should be considered the mainline. This |
| 53 | option specifies the parent number (starting from 1) of |
| 54 | the mainline and allows revert to reverse the change |
| 55 | relative to the specified parent. |
Junio C Hamano | f123149 | 2008-12-22 08:27:21 | [diff] [blame] | 56 | + |
| 57 | Reverting a merge commit declares that you will never want the tree changes |
| 58 | brought in by the merge. As a result, later merges will only bring in tree |
| 59 | changes introduced by commits that are not ancestors of the previously |
| 60 | reverted merge. This may or may not be what you want. |
| 61 | + |
| 62 | See the link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for |
| 63 | more details. |
Junio C Hamano | d814b6d | 2007-11-04 11:13:49 | [diff] [blame] | 64 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 65 | --no-edit:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 66 | With this option, 'git revert' will not start the commit |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 67 | message editor. |
| 68 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 69 | -n:: |
| 70 | --no-commit:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 71 | Usually the command automatically creates some commits with |
| 72 | commit log messages stating which commits were |
| 73 | reverted. This flag applies the changes necessary |
| 74 | to revert the named commits to your working tree |
| 75 | and the index, but does not make the commits. In addition, |
Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 76 | when this option is used, your index does not have to match |
| 77 | the HEAD commit. The revert is done against the |
| 78 | beginning state of your index. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 79 | + |
| 80 | This is useful when reverting more than one commits' |
Junio C Hamano | f69a0a0 | 2008-07-17 08:08:47 | [diff] [blame] | 81 | effect to your index in a row. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 82 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 83 | -s:: |
| 84 | --signoff:: |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 85 | Add Signed-off-by line at the end of the commit message. |
| 86 | |
Junio C Hamano | 23e3f53 | 2011-02-10 02:05:29 | [diff] [blame] | 87 | --strategy=<strategy>:: |
| 88 | Use the given merge strategy. Should only be used once. |
| 89 | See the MERGE STRATEGIES section in linkgit:git-merge[1] |
| 90 | for details. |
| 91 | |
| 92 | -X<option>:: |
| 93 | --strategy-option=<option>:: |
| 94 | Pass the merge strategy-specific option through to the |
| 95 | merge strategy. See linkgit:git-merge[1] for details. |
| 96 | |
Junio C Hamano | 8fb66e5 | 2011-10-05 20:59:51 | [diff] [blame] | 97 | SEQUENCER SUBCOMMANDS |
| 98 | --------------------- |
| 99 | include::sequencer.txt[] |
| 100 | |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 101 | EXAMPLES |
| 102 | -------- |
Junio C Hamano | 16ebcd0 | 2011-08-05 00:05:45 | [diff] [blame] | 103 | `git revert HEAD~3`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 104 | |
| 105 | Revert the changes specified by the fourth last commit in HEAD |
| 106 | and create a new commit with the reverted changes. |
| 107 | |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 108 | `git revert -n master~5..master~2`:: |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 109 | |
| 110 | Revert the changes done by commits from the fifth last commit |
| 111 | in master (included) to the third last commit in master |
| 112 | (included), but do not create any commit with the reverted |
| 113 | changes. The revert only modifies the working tree and the |
| 114 | index. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 115 | |
Junio C Hamano | 89a5734 | 2010-06-22 23:22:55 | [diff] [blame] | 116 | SEE ALSO |
| 117 | -------- |
| 118 | linkgit:git-cherry-pick[1] |
| 119 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 120 | GIT |
| 121 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 122 | Part of the linkgit:git[1] suite |