blob: a4e0a779de6a8e2de7ec9012bc66f15ca351e2aa [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-reset(1)
2============
3
4NAME
5----
Junio C Hamano01078922006-03-10 00:31:476git-reset - Reset current HEAD to the specified state
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamanod793de52006-12-26 09:11:4310[verse]
Junio C Hamano422cfec2007-11-08 08:07:4511'git-reset' [--mixed | --soft | --hard] [-q] [<commit>]
Junio C Hamano14b76482008-01-05 10:32:2612'git-reset' [--mixed] [-q] [<commit>] [--] <paths>...
Junio C Hamano1a4e8412005-12-27 08:17:2313
14DESCRIPTION
15-----------
16Sets the current head to the specified commit and optionally resets the
17index and working tree to match.
18
19This command is useful if you notice some small error in a recent
20commit (or set of commits) and want to redo that part without showing
21the undo in the history.
22
23If you want to undo a commit other than the latest on a branch,
Junio C Hamano35738e82008-01-07 07:55:4624linkgit:git-revert[1] is your friend.
Junio C Hamano1a4e8412005-12-27 08:17:2325
Junio C Hamanod793de52006-12-26 09:11:4326The second form with 'paths' is used to revert selected paths in
27the index from a given commit, without moving HEAD.
28
29
Junio C Hamano1a4e8412005-12-27 08:17:2330OPTIONS
31-------
32--mixed::
Junio C Hamano341071d2006-06-04 07:24:4833Resets the index but not the working tree (i.e., the changed files
Junio C Hamano1a4e8412005-12-27 08:17:2334are preserved but not marked for commit) and reports what has not
35been updated. This is the default action.
36
37--soft::
38Does not touch the index file nor the working tree at all, but
39requires them to be in a good order. This leaves all your changed
Junio C Hamano35738e82008-01-07 07:55:4640files "Added but not yet committed", as linkgit:git-status[1] would
Junio C Hamano1a4e8412005-12-27 08:17:2341put it.
42
43--hard::
44Matches the working tree and index to that of the tree being
45switched to. Any changes to tracked files in the working tree
Junio C Hamanod793de52006-12-26 09:11:4346since <commit> are lost.
Junio C Hamano1a4e8412005-12-27 08:17:2347
Junio C Hamano422cfec2007-11-08 08:07:4548-q::
49Be quiet, only report errors.
50
Junio C Hamanod793de52006-12-26 09:11:4351<commit>::
Junio C Hamano14b76482008-01-05 10:32:2652Commit to make the current HEAD. If not given defaults to HEAD.
Junio C Hamano1a4e8412005-12-27 08:17:2353
54Examples
Junio C Hamano1bb569e2006-05-05 23:14:2555--------
Junio C Hamano1a4e8412005-12-27 08:17:2356
57Undo a commit and redo::
58+
59------------
60$ git commit ...
Junio C Hamanoc8d88c22006-04-29 07:02:0161$ git reset --soft HEAD^ <1>
62$ edit <2>
63$ git commit -a -c ORIG_HEAD <3>
64------------
65+
Junio C Hamano1a4e8412005-12-27 08:17:2366<1> This is most often done when you remembered what you
67just committed is incomplete, or you misspelled your commit
68message, or both. Leaves working tree as it was before "reset".
Junio C Hamano092f5f02007-08-02 07:23:3869<2> Make corrections to working tree files.
Junio C Hamano1a4e8412005-12-27 08:17:2370<3> "reset" copies the old head to .git/ORIG_HEAD; redo the
71commit by starting with its log message. If you do not need to
72edit the message further, you can give -C option instead.
Junio C Hamano47b9acd2007-04-24 07:34:3473+
Junio C Hamano35738e82008-01-07 07:55:4674See also the --amend option to linkgit:git-commit[1].
Junio C Hamano1a4e8412005-12-27 08:17:2375
76Undo commits permanently::
77+
78------------
79$ git commit ...
Junio C Hamanoc8d88c22006-04-29 07:02:0180$ git reset --hard HEAD~3 <1>
81------------
82+
Junio C Hamano1a4e8412005-12-27 08:17:2383<1> The last three commits (HEAD, HEAD^, and HEAD~2) were bad
84and you do not want to ever see them again. Do *not* do this if
85you have already given these commits to somebody else.
Junio C Hamano1a4e8412005-12-27 08:17:2386
87Undo a commit, making it a topic branch::
88+
89------------
Junio C Hamanoc8d88c22006-04-29 07:02:0190$ git branch topic/wip <1>
91$ git reset --hard HEAD~3 <2>
92$ git checkout topic/wip <3>
93------------
94+
Junio C Hamano1a4e8412005-12-27 08:17:2395<1> You have made some commits, but realize they were premature
96to be in the "master" branch. You want to continue polishing
97them in a topic branch, so create "topic/wip" branch off of the
98current HEAD.
99<2> Rewind the master branch to get rid of those three commits.
100<3> Switch to "topic/wip" branch and keep working.
Junio C Hamano1a4e8412005-12-27 08:17:23101
Junio C Hamano89d4e0f2007-02-18 00:34:59102Undo add::
Junio C Hamano1a4e8412005-12-27 08:17:23103+
104------------
Junio C Hamanoc8d88c22006-04-29 07:02:01105$ edit <1>
Junio C Hamano89d4e0f2007-02-18 00:34:59106$ git add frotz.c filfre.c
Junio C Hamanoc8d88c22006-04-29 07:02:01107$ mailx <2>
108$ git reset <3>
109$ git pull git://info.example.com/ nitfol <4>
110------------
111+
Junio C Hamano092f5f02007-08-02 07:23:38112<1> You are happily working on something, and find the changes
Junio C Hamano1a4e8412005-12-27 08:17:23113in these files are in good order. You do not want to see them
114when you run "git diff", because you plan to work on other files
115and changes with these files are distracting.
Junio C Hamano092f5f02007-08-02 07:23:38116<2> Somebody asks you to pull, and the changes sounds worthy of merging.
117<3> However, you already dirtied the index (i.e. your index does
Junio C Hamano1a4e8412005-12-27 08:17:23118not match the HEAD commit). But you know the pull you are going
119to make does not affect frotz.c nor filfre.c, so you revert the
120index changes for these two files. Your changes in working tree
121remain there.
Junio C Hamano092f5f02007-08-02 07:23:38122<4> Then you can pull and merge, leaving frotz.c and filfre.c
Junio C Hamano1a4e8412005-12-27 08:17:23123changes still in the working tree.
Junio C Hamano1a4e8412005-12-27 08:17:23124
125Undo a merge or pull::
126+
127------------
Junio C Hamanoc8d88c22006-04-29 07:02:01128$ git pull <1>
Junio C Hamano1a4e8412005-12-27 08:17:23129Auto-merging nitfol
130CONFLICT (content): Merge conflict in nitfol
131Automatic merge failed/prevented; fix up by hand
Junio C Hamanoc8d88c22006-04-29 07:02:01132$ git reset --hard <2>
133$ git pull . topic/branch <3>
134Updating from 41223... to 13134...
135Fast forward
136$ git reset --hard ORIG_HEAD <4>
137------------
138+
Junio C Hamano092f5f02007-08-02 07:23:38139<1> Try to update from the upstream resulted in a lot of
Junio C Hamano1a4e8412005-12-27 08:17:23140conflicts; you were not ready to spend a lot of time merging
141right now, so you decide to do that later.
142<2> "pull" has not made merge commit, so "git reset --hard"
143which is a synonym for "git reset --hard HEAD" clears the mess
144from the index file and the working tree.
Junio C Hamano092f5f02007-08-02 07:23:38145<3> Merge a topic branch into the current branch, which resulted
Junio C Hamano1a4e8412005-12-27 08:17:23146in a fast forward.
Junio C Hamano092f5f02007-08-02 07:23:38147<4> But you decided that the topic branch is not ready for public
Junio C Hamano1a4e8412005-12-27 08:17:23148consumption yet. "pull" or "merge" always leaves the original
149tip of the current branch in ORIG_HEAD, so resetting hard to it
150brings your index file and the working tree back to that state,
151and resets the tip of the branch to that commit.
Junio C Hamano1a4e8412005-12-27 08:17:23152
Junio C Hamano74e8a2d2006-01-14 03:58:41153Interrupted workflow::
154+
Junio C Hamanoa6331a82006-01-22 07:50:33155Suppose you are interrupted by an urgent fix request while you
156are in the middle of a large change. The files in your
Junio C Hamano74e8a2d2006-01-14 03:58:41157working tree are not in any shape to be committed yet, but you
158need to get to the other branch for a quick bugfix.
159+
160------------
161$ git checkout feature ;# you were working in "feature" branch and
162$ work work work ;# got interrupted
Junio C Hamano7ae0ab22007-11-03 02:46:46163$ git commit -a -m "snapshot WIP" <1>
Junio C Hamano74e8a2d2006-01-14 03:58:41164$ git checkout master
165$ fix fix fix
166$ git commit ;# commit with real log
167$ git checkout feature
Junio C Hamanoc8d88c22006-04-29 07:02:01168$ git reset --soft HEAD^ ;# go back to WIP state <2>
169$ git reset <3>
170------------
171+
Junio C Hamano74e8a2d2006-01-14 03:58:41172<1> This commit will get blown away so a throw-away log message is OK.
Junio C Hamanoa6331a82006-01-22 07:50:33173<2> This removes the 'WIP' commit from the commit history, and sets
174 your working tree to the state just before you made that snapshot.
Junio C Hamanoc8d88c22006-04-29 07:02:01175<3> At this point the index file still has all the WIP changes you
176 committed as 'snapshot WIP'. This updates the index to show your
177 WIP files as uncommitted.
Junio C Hamano74e8a2d2006-01-14 03:58:41178
Junio C Hamano1a4e8412005-12-27 08:17:23179Author
180------
181Written by Junio C Hamano <junkio@cox.net> and Linus Torvalds <torvalds@osdl.org>
182
183Documentation
184--------------
185Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
186
187GIT
188---
Junio C Hamano35738e82008-01-07 07:55:46189Part of the linkgit:git[7] suite