git-revert.txt 3.7 KB
Newer Older
Junio C Hamano's avatar
Junio C Hamano committed
1 2
git-revert(1)
=============
3 4 5

NAME
----
6
git-revert - Revert some existing commits
7 8 9

SYNOPSIS
--------
10
[verse]
11
'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...
12
'git revert' --continue
13
'git revert' --quit
14
'git revert' --abort
15 16 17 18

DESCRIPTION
-----------

19 20 21 22 23 24 25
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).

Note: 'git revert' is used to record some new commits to reverse the
effect of some earlier commits (often only a faulty one).  If you want to
26 27 28
throw away all uncommitted changes in your working directory, you
should see linkgit:git-reset[1], particularly the '--hard' option.  If
you want to extract specific files as they were in another commit, you
29
should see linkgit:git-checkout[1], specifically the `git checkout
30
<commit> -- <filename>` syntax.  Take care with these alternatives as
31 32
both will discard uncommitted changes in your working directory.

33 34
OPTIONS
-------
35 36
<commit>...::
	Commits to revert.
37
	For a more complete list of ways to spell commit names, see
38
	linkgit:gitrevisions[7].
39 40 41
	Sets of commits can also be given but no traversal is done by
	default, see linkgit:git-rev-list[1] and its '--no-walk'
	option.
42

43 44
-e::
--edit::
45
	With this option, 'git revert' will let you edit the commit
46
	message prior to committing the revert. This is the default if
47 48
	you run the command from a terminal.

49 50
-m parent-number::
--mainline parent-number::
51 52 53 54 55
	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.
56 57 58 59 60 61 62 63
+
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.
+
See the link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for
more details.
64

65
--no-edit::
66
	With this option, 'git revert' will not start the commit
67 68
	message editor.

69 70
-n::
--no-commit::
71 72 73 74 75
	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,
76 77 78
	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.
79 80
+
This is useful when reverting more than one commits'
81
effect to your index in a row.
82

83 84
-s::
--signoff::
85 86
	Add Signed-off-by line at the end of the commit message.

87 88 89 90 91 92 93 94 95 96
--strategy=<strategy>::
	Use the given merge strategy.  Should only be used once.
	See the MERGE STRATEGIES section in linkgit:git-merge[1]
	for details.

-X<option>::
--strategy-option=<option>::
	Pass the merge strategy-specific option through to the
	merge strategy.  See linkgit:git-merge[1] for details.

97 98 99 100
SEQUENCER SUBCOMMANDS
---------------------
include::sequencer.txt[]

101 102
EXAMPLES
--------
103
`git revert HEAD~3`::
104 105 106 107

	Revert the changes specified by the fourth last commit in HEAD
	and create a new commit with the reverted changes.

108
`git revert -n master~5..master~2`::
109 110 111 112 113 114

	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.
115

116 117 118 119
SEE ALSO
--------
linkgit:git-cherry-pick[1]

120 121
GIT
---
122
Part of the linkgit:git[1] suite