blob: 8be5de3530733579e34f6911a8638710c111f6ab [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamano01078922006-03-10 00:31:476<meta name="generator" content="AsciiDoc 7.0.2" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229include::./stylesheets/xhtml11-manpage.css[]
230/* Workarounds for IE6's broken and incomplete CSS2. */
231
232div.sidebar-content {
233 background: #ffffee;
234 border: 1px solid silver;
235 padding: 0.5em;
236}
237div.sidebar-title, div.image-title {
238 font-family: sans-serif;
239 font-weight: bold;
240 margin-top: 0.0em;
241 margin-bottom: 0.5em;
242}
243
244div.listingblock div.content {
245 border: 1px solid silver;
246 background: #f4f4f4;
247 padding: 0.5em;
248}
249
250div.quoteblock-content {
251 padding-left: 2.0em;
252}
253
254div.exampleblock-content {
255 border-left: 2px solid silver;
256 padding-left: 0.5em;
257}
258</style>
259<title>git-reset(1)</title>
260</head>
261<body>
262<div id="header">
263<h1>
264git-reset(1) Manual Page
265</h1>
266<h2>NAME</h2>
267<div class="sectionbody">
268<p>git-reset -
Junio C Hamano01078922006-03-10 00:31:47269 Reset current HEAD to the specified state
Junio C Hamano1a4e8412005-12-27 08:17:23270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
275<p><em>git-reset</em> [--mixed | --soft | --hard] [&lt;commit-ish&gt;]</p>
276</div>
277<h2>DESCRIPTION</h2>
278<div class="sectionbody">
279<p>Sets the current head to the specified commit and optionally resets the
280index and working tree to match.</p>
281<p>This command is useful if you notice some small error in a recent
282commit (or set of commits) and want to redo that part without showing
283the undo in the history.</p>
284<p>If you want to undo a commit other than the latest on a branch,
285<a href="git-revert.html">git-revert(1)</a> is your friend.</p>
286</div>
287<h2>OPTIONS</h2>
288<div class="sectionbody">
289<dl>
290<dt>
291--mixed
292</dt>
293<dd>
294<p>
295 Resets the index but not the working tree (ie, the changed files
296 are preserved but not marked for commit) and reports what has not
297 been updated. This is the default action.
298</p>
299</dd>
300<dt>
301--soft
302</dt>
303<dd>
304<p>
305 Does not touch the index file nor the working tree at all, but
306 requires them to be in a good order. This leaves all your changed
307 files "Updated but not checked in", as <a href="git-status.html">git-status(1)</a> would
308 put it.
309</p>
310</dd>
311<dt>
312--hard
313</dt>
314<dd>
315<p>
316 Matches the working tree and index to that of the tree being
317 switched to. Any changes to tracked files in the working tree
318 since &lt;commit-ish&gt; are lost.
319</p>
320</dd>
321<dt>
322&lt;commit-ish&gt;
323</dt>
324<dd>
325<p>
326 Commit to make the current HEAD.
327</p>
328</dd>
329</dl>
Junio C Hamano1bb569e2006-05-05 23:14:25330</div>
331<h2>Examples</h2>
332<div class="sectionbody">
Junio C Hamano1a4e8412005-12-27 08:17:23333<dl>
334<dt>
335Undo a commit and redo
336</dt>
337<dd>
338<div class="listingblock">
339<div class="content">
340<pre><tt>$ git commit ...
Junio C Hamanoc8d88c22006-04-29 07:02:01341$ git reset --soft HEAD^ <b>(1)</b>
342$ edit <b>(2)</b>
343$ git commit -a -c ORIG_HEAD <b>(3)</b></tt></pre>
344</div></div>
345<ol>
346<li>
347<p>
348This is most often done when you remembered what you
Junio C Hamano1a4e8412005-12-27 08:17:23349just committed is incomplete, or you misspelled your commit
350message, or both. Leaves working tree as it was before "reset".
Junio C Hamanoc8d88c22006-04-29 07:02:01351</p>
352</li>
353<li>
354<p>
355make corrections to working tree files.
356</p>
357</li>
358<li>
359<p>
360"reset" copies the old head to .git/ORIG_HEAD; redo the
Junio C Hamano1a4e8412005-12-27 08:17:23361commit by starting with its log message. If you do not need to
Junio C Hamanoc8d88c22006-04-29 07:02:01362edit the message further, you can give -C option instead.
363</p>
364</li>
365</ol>
Junio C Hamano1a4e8412005-12-27 08:17:23366</dd>
367<dt>
368Undo commits permanently
369</dt>
370<dd>
371<div class="listingblock">
372<div class="content">
373<pre><tt>$ git commit ...
Junio C Hamanoc8d88c22006-04-29 07:02:01374$ git reset --hard HEAD~3 <b>(1)</b></tt></pre>
Junio C Hamano1a4e8412005-12-27 08:17:23375</div></div>
Junio C Hamanoc8d88c22006-04-29 07:02:01376<ol>
377<li>
378<p>
379The last three commits (HEAD, HEAD^, and HEAD~2) were bad
380and you do not want to ever see them again. Do <strong>not</strong> do this if
381you have already given these commits to somebody else.
382</p>
383</li>
384</ol>
Junio C Hamano1a4e8412005-12-27 08:17:23385</dd>
386<dt>
387Undo a commit, making it a topic branch
388</dt>
389<dd>
390<div class="listingblock">
391<div class="content">
Junio C Hamanoc8d88c22006-04-29 07:02:01392<pre><tt>$ git branch topic/wip <b>(1)</b>
393$ git reset --hard HEAD~3 <b>(2)</b>
394$ git checkout topic/wip <b>(3)</b></tt></pre>
395</div></div>
396<ol>
397<li>
398<p>
399You have made some commits, but realize they were premature
Junio C Hamano1a4e8412005-12-27 08:17:23400to be in the "master" branch. You want to continue polishing
401them in a topic branch, so create "topic/wip" branch off of the
402current HEAD.
Junio C Hamanoc8d88c22006-04-29 07:02:01403</p>
404</li>
405<li>
406<p>
407Rewind the master branch to get rid of those three commits.
408</p>
409</li>
410<li>
411<p>
412Switch to "topic/wip" branch and keep working.
413</p>
414</li>
415</ol>
Junio C Hamano1a4e8412005-12-27 08:17:23416</dd>
417<dt>
418Undo update-index
419</dt>
420<dd>
421<div class="listingblock">
422<div class="content">
Junio C Hamanoc8d88c22006-04-29 07:02:01423<pre><tt>$ edit <b>(1)</b>
Junio C Hamano1a4e8412005-12-27 08:17:23424$ git-update-index frotz.c filfre.c
Junio C Hamanoc8d88c22006-04-29 07:02:01425$ mailx <b>(2)</b>
426$ git reset <b>(3)</b>
427$ git pull git://info.example.com/ nitfol <b>(4)</b></tt></pre>
428</div></div>
429<ol>
430<li>
431<p>
432you are happily working on something, and find the changes
Junio C Hamano1a4e8412005-12-27 08:17:23433in these files are in good order. You do not want to see them
434when you run "git diff", because you plan to work on other files
435and changes with these files are distracting.
Junio C Hamanoc8d88c22006-04-29 07:02:01436</p>
437</li>
438<li>
439<p>
440somebody asks you to pull, and the changes sounds worthy of merging.
441</p>
442</li>
443<li>
444<p>
445however, you already dirtied the index (i.e. your index does
Junio C Hamano1a4e8412005-12-27 08:17:23446not match the HEAD commit). But you know the pull you are going
447to make does not affect frotz.c nor filfre.c, so you revert the
448index changes for these two files. Your changes in working tree
449remain there.
Junio C Hamanoc8d88c22006-04-29 07:02:01450</p>
451</li>
452<li>
453<p>
454then you can pull and merge, leaving frotz.c and filfre.c
455changes still in the working tree.
456</p>
457</li>
458</ol>
Junio C Hamano1a4e8412005-12-27 08:17:23459</dd>
460<dt>
461Undo a merge or pull
462</dt>
463<dd>
464<div class="listingblock">
465<div class="content">
Junio C Hamanoc8d88c22006-04-29 07:02:01466<pre><tt>$ git pull <b>(1)</b>
Junio C Hamano1a4e8412005-12-27 08:17:23467Trying really trivial in-index merge...
468fatal: Merge requires file-level merging
469Nope.
470...
471Auto-merging nitfol
472CONFLICT (content): Merge conflict in nitfol
473Automatic merge failed/prevented; fix up by hand
Junio C Hamanoc8d88c22006-04-29 07:02:01474$ git reset --hard <b>(2)</b>
475$ git pull . topic/branch <b>(3)</b>
Junio C Hamano1a4e8412005-12-27 08:17:23476Updating from 41223... to 13134...
477Fast forward
Junio C Hamanoc8d88c22006-04-29 07:02:01478$ git reset --hard ORIG_HEAD <b>(4)</b></tt></pre>
479</div></div>
480<ol>
481<li>
482<p>
483try to update from the upstream resulted in a lot of
484conflicts; you were not ready to spend a lot of time merging
485right now, so you decide to do that later.
486</p>
487</li>
488<li>
489<p>
490"pull" has not made merge commit, so "git reset --hard"
491which is a synonym for "git reset --hard HEAD" clears the mess
492from the index file and the working tree.
493</p>
494</li>
495<li>
496<p>
497merge a topic branch into the current branch, which resulted
Junio C Hamano1a4e8412005-12-27 08:17:23498in a fast forward.
Junio C Hamanoc8d88c22006-04-29 07:02:01499</p>
500</li>
501<li>
502<p>
503but you decided that the topic branch is not ready for public
Junio C Hamano1a4e8412005-12-27 08:17:23504consumption yet. "pull" or "merge" always leaves the original
505tip of the current branch in ORIG_HEAD, so resetting hard to it
506brings your index file and the working tree back to that state,
Junio C Hamanoc8d88c22006-04-29 07:02:01507and resets the tip of the branch to that commit.
508</p>
509</li>
510</ol>
Junio C Hamano1a4e8412005-12-27 08:17:23511</dd>
Junio C Hamano74e8a2d2006-01-14 03:58:41512<dt>
513Interrupted workflow
514</dt>
515<dd>
Junio C Hamanoa6331a82006-01-22 07:50:33516<p>Suppose you are interrupted by an urgent fix request while you
517are in the middle of a large change. The files in your
Junio C Hamano74e8a2d2006-01-14 03:58:41518working tree are not in any shape to be committed yet, but you
519need to get to the other branch for a quick bugfix.</p>
520<div class="listingblock">
521<div class="content">
522<pre><tt>$ git checkout feature ;# you were working in "feature" branch and
523$ work work work ;# got interrupted
Junio C Hamanoc8d88c22006-04-29 07:02:01524$ git commit -a -m 'snapshot WIP' <b>(1)</b>
Junio C Hamano74e8a2d2006-01-14 03:58:41525$ git checkout master
526$ fix fix fix
527$ git commit ;# commit with real log
528$ git checkout feature
Junio C Hamanoc8d88c22006-04-29 07:02:01529$ git reset --soft HEAD^ ;# go back to WIP state <b>(2)</b>
530$ git reset <b>(3)</b></tt></pre>
Junio C Hamano74e8a2d2006-01-14 03:58:41531</div></div>
Junio C Hamanoc8d88c22006-04-29 07:02:01532<ol>
533<li>
534<p>
535This commit will get blown away so a throw-away log message is OK.
536</p>
537</li>
538<li>
539<p>
540This removes the <em>WIP</em> commit from the commit history, and sets
541 your working tree to the state just before you made that snapshot.
542</p>
543</li>
544<li>
545<p>
546At this point the index file still has all the WIP changes you
547 committed as <em>snapshot WIP</em>. This updates the index to show your
548 WIP files as uncommitted.
549</p>
550</li>
551</ol>
Junio C Hamano74e8a2d2006-01-14 03:58:41552</dd>
Junio C Hamano1a4e8412005-12-27 08:17:23553</dl>
554</div>
555<h2>Author</h2>
556<div class="sectionbody">
557<p>Written by Junio C Hamano &lt;junkio@cox.net&gt; and Linus Torvalds &lt;torvalds@osdl.org&gt;</p>
558</div>
559<h2>Documentation</h2>
560<div class="sectionbody">
561<p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p>
562</div>
563<h2>GIT</h2>
564<div class="sectionbody">
565<p>Part of the <a href="git.html">git(7)</a> suite</p>
566</div>
567<div id="footer">
568<div id="footer-text">
Junio C Hamano1bb569e2006-05-05 23:14:25569Last updated 05-May-2006 23:14:15 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23570</div>
571</div>
572</body>
573</html>