1 .\"Generated by db2man.xsl. Don't modify this, modify the source.
10 .de Sp \" Vertical space (when we can't use .PP)
16 .ie \\n(.$>=3 .ne \\$3
20 .TH "GIT-RESET" 1 "" "" ""
22 git-reset \- Reset current HEAD to the specified state
26 \fIgit\-reset\fR [\-\-mixed | \-\-soft | \-\-hard] [<commit\-ish>]
31 Sets the current head to the specified commit and optionally resets the index and working tree to match\&.
34 This command is useful if you notice some small error in a recent commit (or set of commits) and want to redo that part without showing the undo in the history\&.
37 If you want to undo a commit other than the latest on a branch, \fBgit\-revert\fR(1) is your friend\&.
43 Resets the index but not the working tree (ie, the changed files are preserved but not marked for commit) and reports what has not been updated\&. This is the default action\&.
47 Does not touch the index file nor the working tree at all, but requires them to be in a good order\&. This leaves all your changed files "Updated but not checked in", as \fBgit\-status\fR(1) would put it\&.
51 Matches the working tree and index to that of the tree being switched to\&. Any changes to tracked files in the working tree since <commit\-ish> are lost\&.
55 Commit to make the current HEAD\&.
60 Undo a commit and redo
63 $ git commit \&.\&.\&.
64 $ git reset \-\-soft HEAD^
66 $ git commit \-a \-c ORIG_HEAD
68 This is most often done when you remembered what you
69 just committed is incomplete, or you misspelled your commit
70 message, or both\&. Leaves working tree as it was before "reset"\&.
71 make corrections to working tree files\&.
72 "reset" copies the old head to \&.git/ORIG_HEAD; redo the
73 commit by starting with its log message\&. If you do not need to
74 edit the message further, you can give \-C option instead\&.
78 Undo commits permanently
81 $ git commit \&.\&.\&.
82 $ git reset \-\-hard HEAD~3
84 The last three commits (HEAD, HEAD^, and HEAD~2) were bad
85 and you do not want to ever see them again\&. Do *not* do this if
86 you have already given these commits to somebody else\&.
90 Undo a commit, making it a topic branch
93 $ git branch topic/wip
94 $ git reset \-\-hard HEAD~3
95 $ git checkout topic/wip
97 You have made some commits, but realize they were premature
98 to be in the "master" branch\&. You want to continue polishing
99 them in a topic branch, so create "topic/wip" branch off of the
101 Rewind the master branch to get rid of those three commits\&.
102 Switch to "topic/wip" branch and keep working\&.
110 $ git\-update\-index frotz\&.c filfre\&.c
113 $ git pull git://info\&.example\&.com/ nitfol
115 you are happily working on something, and find the changes
116 in these files are in good order\&. You do not want to see them
117 when you run "git diff", because you plan to work on other files
118 and changes with these files are distracting\&.
119 somebody asks you to pull, and the changes sounds worthy of merging\&.
120 however, you already dirtied the index (i\&.e\&. your index does
121 not match the HEAD commit)\&. But you know the pull you are going
122 to make does not affect frotz\&.c nor filfre\&.c, so you revert the
123 index changes for these two files\&. Your changes in working tree
125 then you can pull and merge, leaving frotz\&.c and filfre\&.c
126 changes still in the working tree\&.
134 Trying really trivial in\-index merge\&.\&.\&.
135 fatal: Merge requires file\-level merging
139 CONFLICT (content): Merge conflict in nitfol
140 Automatic merge failed/prevented; fix up by hand
143 try to update from the upstream resulted in a lot of
144 conflicts; you were not ready to spend a lot of time merging
145 right now, so you decide to do that later\&.
146 "pull" has not made merge commit, so "git reset \-\-hard"
147 which is a synonym for "git reset \-\-hard HEAD" clears the mess
148 from the index file and the working tree\&.
150 $ git pull \&. topic/branch
151 Updating from 41223\&.\&.\&. to 13134\&.\&.\&.
153 $ git reset \-\-hard ORIG_HEAD
155 merge a topic branch into the current branch, which resulted
157 but you decided that the topic branch is not ready for public
158 consumption yet\&. "pull" or "merge" always leaves the original
159 tip of the current branch in ORIG_HEAD, so resetting hard to it
160 brings your index file and the working tree back to that state,
161 and resets the tip of the branch to that commit\&.
166 Suppose you are interrupted by an urgent fix request while you are in the middle of a large change\&. The files in your working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix\&.
169 $ git checkout feature ;# you were working in "feature" branch and
170 $ work work work ;# got interrupted
171 $ git commit \-a \-m 'snapshot WIP'
172 $ git checkout master
174 $ git commit ;# commit with real log
175 $ git checkout feature
176 $ git reset \-\-soft HEAD^ ;# go back to WIP state
179 This commit will get blown away so a throw\-away log message is OK\&.
180 This removes the 'WIP' commit from the commit history, and sets
181 your working tree to the state just before you made that snapshot\&.
182 After , the index file still has all the WIP changes you
183 committed in \&. This sets it to the last commit you were
184 basing the WIP changes on\&.
190 Written by Junio C Hamano <junkio@cox\&.net> and Linus Torvalds <torvalds@osdl\&.org>
195 Documentation by Junio C Hamano and the git\-list <git@vger\&.kernel\&.org>\&.
200 Part of the \fBgit\fR(7) suite