1GIT-RESET(1)                      Git Manual                      GIT-RESET(1)
2
3
4

NAME

6       git-reset - Reset current HEAD to the specified state
7

SYNOPSIS

9           git-reset [--mixed | --soft | --hard] [<commit>]
10           git-reset [--mixed] <commit> [--] <paths>...
11

DESCRIPTION

13       Sets the current head to the specified commit and optionally resets the
14       index and working tree to match.
15
16       This command is useful if you notice some small error in a recent
17       commit (or set of commits) and want to redo that part without showing
18       the undo in the history.
19
20       If you want to undo a commit other than the latest on a branch, git-
21       revert(1) is your friend.
22
23       The second form with paths is used to revert selected paths in the
24       index from a given commit, without moving HEAD.
25

OPTIONS

27       --mixed
28           Resets the index but not the working tree (i.e., the changed files
29           are preserved but not marked for commit) and reports what has not
30           been updated. This is the default action.
31
32       --soft
33           Does not touch the index file nor the working tree at all, but
34           requires them to be in a good order. This leaves all your changed
35           files "Added but not yet committed", as git-status(1) would put it.
36
37       --hard
38           Matches the working tree and index to that of the tree being
39           switched to. Any changes to tracked files in the working tree since
40           <commit> are lost.
41
42       <commit>
43           Commit to make the current HEAD.
44

EXAMPLES

46       Undo a commit and redo
47
48
49               $ git commit ...
50               $ git reset --soft HEAD^      (1)
51               $ edit                        (2)
52               $ git commit -a -c ORIG_HEAD  (3)
53
54
55           1. This is most often done when you remembered what you just
56           committed is incomplete, or you misspelled your commit message, or
57           both. Leaves working tree as it was before "reset".
58           2. Make corrections to working tree files.
59           3. "reset" copies the old head to .git/ORIG_HEAD; redo the commit
60           by starting with its log message. If you do not need to edit the
61           message further, you can give -C option instead.
62
63           See also the --amend option to git-commit(1).
64
65       Undo commits permanently
66
67
68               $ git commit ...
69               $ git reset --hard HEAD~3   (1)
70
71
72           1. The last three commits (HEAD, HEAD^, and HEAD~2) were bad and
73           you do not want to ever see them again. Do not do this if you have
74           already given these commits to somebody else.
75
76       Undo a commit, making it a topic branch
77
78
79               $ git branch topic/wip     (1)
80               $ git reset --hard HEAD~3  (2)
81               $ git checkout topic/wip   (3)
82
83
84           1. You have made some commits, but realize they were premature to
85           be in the "master" branch. You want to continue polishing them in a
86           topic branch, so create "topic/wip" branch off of the current HEAD.
87           2. Rewind the master branch to get rid of those three commits.
88           3. Switch to "topic/wip" branch and keep working.
89
90       Undo add
91
92
93               $ edit                                     (1)
94               $ git add frotz.c filfre.c
95               $ mailx                                    (2)
96               $ git reset                                (3)
97               $ git pull git://info.example.com/ nitfol  (4)
98
99
100           1. You are happily working on something, and find the changes in
101           these files are in good order. You do not want to see them when you
102           run "git diff", because you plan to work on other files and changes
103           with these files are distracting.
104           2. Somebody asks you to pull, and the changes sounds worthy of
105           merging.
106           3. However, you already dirtied the index (i.e. your index does not
107           match the HEAD commit). But you know the pull you are going to make
108           does not affect frotz.c nor filfre.c, so you revert the index
109           changes for these two files. Your changes in working tree remain
110           there.
111           4. Then you can pull and merge, leaving frotz.c and filfre.c
112           changes still in the working tree.
113
114       Undo a merge or pull
115
116
117               $ git pull                         (1)
118               Auto-merging nitfol
119               CONFLICT (content): Merge conflict in nitfol
120               Automatic merge failed/prevented; fix up by hand
121               $ git reset --hard                 (2)
122               $ git pull . topic/branch          (3)
123               Updating from 41223... to 13134...
124               Fast forward
125               $ git reset --hard ORIG_HEAD       (4)
126
127
128           1. Try to update from the upstream resulted in a lot of conflicts;
129           you were not ready to spend a lot of time merging right now, so you
130           decide to do that later.
131           2. "pull" has not made merge commit, so "git reset --hard" which is
132           a synonym for "git reset --hard HEAD" clears the mess from the
133           index file and the working tree.
134           3. Merge a topic branch into the current branch, which resulted in
135           a fast forward.
136           4. But you decided that the topic branch is not ready for public
137           consumption yet. "pull" or "merge" always leaves the original tip
138           of the current branch in ORIG_HEAD, so resetting hard to it brings
139           your index file and the working tree back to that state, and resets
140           the tip of the branch to that commit.
141
142       Interrupted workflow
143           Suppose you are interrupted by an urgent fix request while you are
144           in the middle of a large change. The files in your working tree are
145           not in any shape to be committed yet, but you need to get to the
146           other branch for a quick bugfix.
147
148
149
150               $ git checkout feature ;# you were working in "feature" branch and
151               $ work work work       ;# got interrupted
152               $ git commit -a -m ´snapshot WIP´                 (1)
153               $ git checkout master
154               $ fix fix fix
155               $ git commit ;# commit with real log
156               $ git checkout feature
157               $ git reset --soft HEAD^ ;# go back to WIP state  (2)
158               $ git reset                                       (3)
159
160
161           1. This commit will get blown away so a throw-away log message is
162           OK.
163           2. This removes the WIP commit from the commit history, and sets
164           your working tree to the state just before you made that snapshot.
165           3. At this point the index file still has all the WIP changes you
166           committed as snapshot WIP. This updates the index to show your WIP
167           files as uncommitted.
168

AUTHOR

170       Written by Junio C Hamano <junkio@cox.net> and Linus Torvalds
171       <torvalds@osdl.org>
172

DOCUMENTATION

174       Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
175

GIT

177       Part of the git(7) suite
178
179
180
181
182Git 1.5.3.3                       10/09/2007                      GIT-RESET(1)
Impressum