Merge branch 'maint-1.7.3' into maint
[git/git.git] / Documentation / git-revert.txt
1 git-revert(1)
2 =============
3
4 NAME
5 ----
6 git-revert - Revert some existing commits
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...
12
13 DESCRIPTION
14 -----------
15
16 Given one or more existing commits, revert the changes that the
17 related patches introduce, and record some new commits that record
18 them. This requires your working tree to be clean (no modifications
19 from the HEAD commit).
20
21 Note: 'git revert' is used to record some new commits to reverse the
22 effect of some earlier commits (often only a faulty one). If you want to
23 throw away all uncommitted changes in your working directory, you
24 should see linkgit:git-reset[1], particularly the '--hard' option. If
25 you want to extract specific files as they were in another commit, you
26 should see linkgit:git-checkout[1], specifically the `git checkout
27 <commit> \-- <filename>` syntax. Take care with these alternatives as
28 both will discard uncommitted changes in your working directory.
29
30 OPTIONS
31 -------
32 <commit>...::
33 Commits to revert.
34 For a more complete list of ways to spell commit names, see
35 linkgit:gitrevisions[7].
36 Sets of commits can also be given but no traversal is done by
37 default, see linkgit:git-rev-list[1] and its '--no-walk'
38 option.
39
40 -e::
41 --edit::
42 With this option, 'git revert' will let you edit the commit
43 message prior to committing the revert. This is the default if
44 you run the command from a terminal.
45
46 -m parent-number::
47 --mainline parent-number::
48 Usually you cannot revert a merge because you do not know which
49 side of the merge should be considered the mainline. This
50 option specifies the parent number (starting from 1) of
51 the mainline and allows revert to reverse the change
52 relative to the specified parent.
53 +
54 Reverting a merge commit declares that you will never want the tree changes
55 brought in by the merge. As a result, later merges will only bring in tree
56 changes introduced by commits that are not ancestors of the previously
57 reverted merge. This may or may not be what you want.
58 +
59 See the link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for
60 more details.
61
62 --no-edit::
63 With this option, 'git revert' will not start the commit
64 message editor.
65
66 -n::
67 --no-commit::
68 Usually the command automatically creates some commits with
69 commit log messages stating which commits were
70 reverted. This flag applies the changes necessary
71 to revert the named commits to your working tree
72 and the index, but does not make the commits. In addition,
73 when this option is used, your index does not have to match
74 the HEAD commit. The revert is done against the
75 beginning state of your index.
76 +
77 This is useful when reverting more than one commits'
78 effect to your index in a row.
79
80 -s::
81 --signoff::
82 Add Signed-off-by line at the end of the commit message.
83
84 --strategy=<strategy>::
85 Use the given merge strategy. Should only be used once.
86 See the MERGE STRATEGIES section in linkgit:git-merge[1]
87 for details.
88
89 -X<option>::
90 --strategy-option=<option>::
91 Pass the merge strategy-specific option through to the
92 merge strategy. See linkgit:git-merge[1] for details.
93
94 EXAMPLES
95 --------
96 `git revert HEAD~3`::
97
98 Revert the changes specified by the fourth last commit in HEAD
99 and create a new commit with the reverted changes.
100
101 `git revert -n master{tilde}5..master{tilde}2`::
102
103 Revert the changes done by commits from the fifth last commit
104 in master (included) to the third last commit in master
105 (included), but do not create any commit with the reverted
106 changes. The revert only modifies the working tree and the
107 index.
108
109 SEE ALSO
110 --------
111 linkgit:git-cherry-pick[1]
112
113 GIT
114 ---
115 Part of the linkgit:git[1] suite