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