Autogenerated HTML docs for v1.6.6-136-g637af
[git/jnareb-git.git] / git-reset.html
blob0eeee7bc0daf06e7ae14ee81521a9deafb9a0ccf
1 <!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" />
6 <meta name="generator" content="AsciiDoc 8.2.5" />
7 <style type="text/css">
8 /* Debug borders */
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 border: 1px solid red;
15 body {
16 margin: 1em 5% 1em 5%;
19 a {
20 color: blue;
21 text-decoration: underline;
23 a:visited {
24 color: fuchsia;
27 em {
28 font-style: italic;
31 strong {
32 font-weight: bold;
35 tt {
36 color: navy;
39 h1, h2, h3, h4, h5, h6 {
40 color: #527bbd;
41 font-family: sans-serif;
42 margin-top: 1.2em;
43 margin-bottom: 0.5em;
44 line-height: 1.3;
47 h1, h2, h3 {
48 border-bottom: 2px solid silver;
50 h2 {
51 padding-top: 0.5em;
53 h3 {
54 float: left;
56 h3 + * {
57 clear: left;
60 div.sectionbody {
61 font-family: serif;
62 margin-left: 0;
65 hr {
66 border: 1px solid silver;
69 p {
70 margin-top: 0.5em;
71 margin-bottom: 0.5em;
74 pre {
75 padding: 0;
76 margin: 0;
79 span#author {
80 color: #527bbd;
81 font-family: sans-serif;
82 font-weight: bold;
83 font-size: 1.1em;
85 span#email {
87 span#revision {
88 font-family: sans-serif;
91 div#footer {
92 font-family: sans-serif;
93 font-size: small;
94 border-top: 2px solid silver;
95 padding-top: 0.5em;
96 margin-top: 4.0em;
98 div#footer-text {
99 float: left;
100 padding-bottom: 0.5em;
102 div#footer-badges {
103 float: right;
104 padding-bottom: 0.5em;
107 div#preamble,
108 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
109 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
110 div.admonitionblock {
111 margin-right: 10%;
112 margin-top: 1.5em;
113 margin-bottom: 1.5em;
115 div.admonitionblock {
116 margin-top: 2.5em;
117 margin-bottom: 2.5em;
120 div.content { /* Block element content. */
121 padding: 0;
124 /* Block element titles. */
125 div.title, caption.title {
126 font-family: sans-serif;
127 font-weight: bold;
128 text-align: left;
129 margin-top: 1.0em;
130 margin-bottom: 0.5em;
132 div.title + * {
133 margin-top: 0;
136 td div.title:first-child {
137 margin-top: 0.0em;
139 div.content div.title:first-child {
140 margin-top: 0.0em;
142 div.content + div.title {
143 margin-top: 0.0em;
146 div.sidebarblock > div.content {
147 background: #ffffee;
148 border: 1px solid silver;
149 padding: 0.5em;
152 div.listingblock {
153 margin-right: 0%;
155 div.listingblock > div.content {
156 border: 1px solid silver;
157 background: #f4f4f4;
158 padding: 0.5em;
161 div.quoteblock > div.content {
162 padding-left: 2.0em;
165 div.attribution {
166 text-align: right;
168 div.verseblock + div.attribution {
169 text-align: left;
172 div.admonitionblock .icon {
173 vertical-align: top;
174 font-size: 1.1em;
175 font-weight: bold;
176 text-decoration: underline;
177 color: #527bbd;
178 padding-right: 0.5em;
180 div.admonitionblock td.content {
181 padding-left: 0.5em;
182 border-left: 2px solid silver;
185 div.exampleblock > div.content {
186 border-left: 2px solid silver;
187 padding: 0.5em;
190 div.verseblock div.content {
191 white-space: pre;
194 div.imageblock div.content { padding-left: 0; }
195 div.imageblock img { border: 1px solid silver; }
196 span.image img { border-style: none; }
198 dl {
199 margin-top: 0.8em;
200 margin-bottom: 0.8em;
202 dt {
203 margin-top: 0.5em;
204 margin-bottom: 0;
205 font-style: italic;
207 dd > *:first-child {
208 margin-top: 0;
211 ul, ol {
212 list-style-position: outside;
214 div.olist2 ol {
215 list-style-type: lower-alpha;
218 div.tableblock > table {
219 border: 3px solid #527bbd;
221 thead {
222 font-family: sans-serif;
223 font-weight: bold;
225 tfoot {
226 font-weight: bold;
229 div.hlist {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
233 div.hlist td {
234 padding-bottom: 5px;
236 td.hlist1 {
237 vertical-align: top;
238 font-style: italic;
239 padding-right: 0.8em;
241 td.hlist2 {
242 vertical-align: top;
245 @media print {
246 div#footer-badges { display: none; }
249 div#toctitle {
250 color: #527bbd;
251 font-family: sans-serif;
252 font-size: 1.1em;
253 font-weight: bold;
254 margin-top: 1.0em;
255 margin-bottom: 0.1em;
258 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
259 margin-top: 0;
260 margin-bottom: 0;
262 div.toclevel2 {
263 margin-left: 2em;
264 font-size: 0.9em;
266 div.toclevel3 {
267 margin-left: 4em;
268 font-size: 0.9em;
270 div.toclevel4 {
271 margin-left: 6em;
272 font-size: 0.9em;
274 include1::./stylesheets/xhtml11-manpage.css[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div.sidebar-content {
278 background: #ffffee;
279 border: 1px solid silver;
280 padding: 0.5em;
282 div.sidebar-title, div.image-title {
283 font-family: sans-serif;
284 font-weight: bold;
285 margin-top: 0.0em;
286 margin-bottom: 0.5em;
289 div.listingblock div.content {
290 border: 1px solid silver;
291 background: #f4f4f4;
292 padding: 0.5em;
295 div.quoteblock-content {
296 padding-left: 2.0em;
299 div.exampleblock-content {
300 border-left: 2px solid silver;
301 padding-left: 0.5em;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc a:visited { color: blue; }
306 </style>
307 <title>git-reset(1)</title>
308 </head>
309 <body>
310 <div id="header">
311 <h1>
312 git-reset(1) Manual Page
313 </h1>
314 <h2>NAME</h2>
315 <div class="sectionbody">
316 <p>git-reset -
317 Reset current HEAD to the specified state
318 </p>
319 </div>
320 </div>
321 <h2>SYNOPSIS</h2>
322 <div class="sectionbody">
323 <div class="verseblock">
324 <div class="content"><em>git reset</em> [--mixed | --soft | --hard | --merge] [-q] [&lt;commit&gt;]
325 <em>git reset</em> [-q] [&lt;commit&gt;] [--] &lt;paths&gt;&#8230;
326 <em>git reset</em> --patch [&lt;commit&gt;] [--] [&lt;paths&gt;&#8230;]</div></div>
327 </div>
328 <h2 id="_description">DESCRIPTION</h2>
329 <div class="sectionbody">
330 <div class="para"><p>Sets the current head to the specified commit and optionally resets the
331 index and working tree to match.</p></div>
332 <div class="para"><p>This command is useful if you notice some small error in a recent
333 commit (or set of commits) and want to redo that part without showing
334 the undo in the history.</p></div>
335 <div class="para"><p>If you want to undo a commit other than the latest on a branch,
336 <a href="git-revert.html">git-revert(1)</a> is your friend.</p></div>
337 <div class="para"><p>The second and third forms with <em>paths</em> and/or --patch are used to
338 revert selected paths in the index from a given commit, without moving
339 HEAD.</p></div>
340 </div>
341 <h2 id="_options">OPTIONS</h2>
342 <div class="sectionbody">
343 <div class="vlist"><dl>
344 <dt>
345 --mixed
346 </dt>
347 <dd>
349 Resets the index but not the working tree (i.e., the changed files
350 are preserved but not marked for commit) and reports what has not
351 been updated. This is the default action.
352 </p>
353 </dd>
354 <dt>
355 --soft
356 </dt>
357 <dd>
359 Does not touch the index file nor the working tree at all, but
360 requires them to be in a good order. This leaves all your changed
361 files "Changes to be committed", as <em>git-status</em> would
362 put it.
363 </p>
364 </dd>
365 <dt>
366 --hard
367 </dt>
368 <dd>
370 Matches the working tree and index to that of the tree being
371 switched to. Any changes to tracked files in the working tree
372 since &lt;commit&gt; are lost.
373 </p>
374 </dd>
375 <dt>
376 --merge
377 </dt>
378 <dd>
380 Resets the index to match the tree recorded by the named commit,
381 and updates the files that are different between the named commit
382 and the current commit in the working tree.
383 </p>
384 </dd>
385 <dt>
387 </dt>
388 <dt>
389 --patch
390 </dt>
391 <dd>
393 Interactively select hunks in the difference between the index
394 and &lt;commit&gt; (defaults to HEAD). The chosen hunks are applied
395 in reverse to the index.
396 </p>
397 <div class="para"><p>This means that <tt>git reset -p</tt> is the opposite of <tt>git add -p</tt> (see
398 <a href="git-add.html">git-add(1)</a>).</p></div>
399 </dd>
400 <dt>
402 </dt>
403 <dt>
404 --quiet
405 </dt>
406 <dd>
408 Be quiet, only report errors.
409 </p>
410 </dd>
411 <dt>
412 &lt;commit&gt;
413 </dt>
414 <dd>
416 Commit to make the current HEAD. If not given defaults to HEAD.
417 </p>
418 </dd>
419 </dl></div>
420 </div>
421 <h2 id="_examples">Examples</h2>
422 <div class="sectionbody">
423 <div class="vlist"><dl>
424 <dt>
425 Undo a commit and redo
426 </dt>
427 <dd>
428 <div class="listingblock">
429 <div class="content">
430 <pre><tt>$ git commit ...
431 $ git reset --soft HEAD^ <b>(1)</b>
432 $ edit <b>(2)</b>
433 $ git commit -a -c ORIG_HEAD <b>(3)</b></tt></pre>
434 </div></div>
435 <div class="colist"><ol>
436 <li>
438 This is most often done when you remembered what you
439 just committed is incomplete, or you misspelled your commit
440 message, or both. Leaves working tree as it was before "reset".
441 </p>
442 </li>
443 <li>
445 Make corrections to working tree files.
446 </p>
447 </li>
448 <li>
450 "reset" copies the old head to .git/ORIG_HEAD; redo the
451 commit by starting with its log message. If you do not need to
452 edit the message further, you can give -C option instead.
453 </p>
454 <div class="para"><p>See also the --amend option to <a href="git-commit.html">git-commit(1)</a>.</p></div>
455 </li>
456 </ol></div>
457 </dd>
458 <dt>
459 Undo commits permanently
460 </dt>
461 <dd>
462 <div class="listingblock">
463 <div class="content">
464 <pre><tt>$ git commit ...
465 $ git reset --hard HEAD~3 <b>(1)</b></tt></pre>
466 </div></div>
467 <div class="colist"><ol>
468 <li>
470 The last three commits (HEAD, HEAD^, and HEAD~2) were bad
471 and you do not want to ever see them again. Do <strong>not</strong> do this if
472 you have already given these commits to somebody else. (See the
473 "RECOVERING FROM UPSTREAM REBASE" section in <a href="git-rebase.html">git-rebase(1)</a> for
474 the implications of doing so.)
475 </p>
476 </li>
477 </ol></div>
478 </dd>
479 <dt>
480 Undo a commit, making it a topic branch
481 </dt>
482 <dd>
483 <div class="listingblock">
484 <div class="content">
485 <pre><tt>$ git branch topic/wip <b>(1)</b>
486 $ git reset --hard HEAD~3 <b>(2)</b>
487 $ git checkout topic/wip <b>(3)</b></tt></pre>
488 </div></div>
489 <div class="colist"><ol>
490 <li>
492 You have made some commits, but realize they were premature
493 to be in the "master" branch. You want to continue polishing
494 them in a topic branch, so create "topic/wip" branch off of the
495 current HEAD.
496 </p>
497 </li>
498 <li>
500 Rewind the master branch to get rid of those three commits.
501 </p>
502 </li>
503 <li>
505 Switch to "topic/wip" branch and keep working.
506 </p>
507 </li>
508 </ol></div>
509 </dd>
510 <dt>
511 Undo add
512 </dt>
513 <dd>
514 <div class="listingblock">
515 <div class="content">
516 <pre><tt>$ edit <b>(1)</b>
517 $ git add frotz.c filfre.c
518 $ mailx <b>(2)</b>
519 $ git reset <b>(3)</b>
520 $ git pull git://info.example.com/ nitfol <b>(4)</b></tt></pre>
521 </div></div>
522 <div class="colist"><ol>
523 <li>
525 You are happily working on something, and find the changes
526 in these files are in good order. You do not want to see them
527 when you run "git diff", because you plan to work on other files
528 and changes with these files are distracting.
529 </p>
530 </li>
531 <li>
533 Somebody asks you to pull, and the changes sounds worthy of merging.
534 </p>
535 </li>
536 <li>
538 However, you already dirtied the index (i.e. your index does
539 not match the HEAD commit). But you know the pull you are going
540 to make does not affect frotz.c nor filfre.c, so you revert the
541 index changes for these two files. Your changes in working tree
542 remain there.
543 </p>
544 </li>
545 <li>
547 Then you can pull and merge, leaving frotz.c and filfre.c
548 changes still in the working tree.
549 </p>
550 </li>
551 </ol></div>
552 </dd>
553 <dt>
554 Undo a merge or pull
555 </dt>
556 <dd>
557 <div class="listingblock">
558 <div class="content">
559 <pre><tt>$ git pull <b>(1)</b>
560 Auto-merging nitfol
561 CONFLICT (content): Merge conflict in nitfol
562 Automatic merge failed; fix conflicts and then commit the result.
563 $ git reset --hard <b>(2)</b>
564 $ git pull . topic/branch <b>(3)</b>
565 Updating from 41223... to 13134...
566 Fast-forward
567 $ git reset --hard ORIG_HEAD <b>(4)</b></tt></pre>
568 </div></div>
569 <div class="colist"><ol>
570 <li>
572 Try to update from the upstream resulted in a lot of
573 conflicts; you were not ready to spend a lot of time merging
574 right now, so you decide to do that later.
575 </p>
576 </li>
577 <li>
579 "pull" has not made merge commit, so "git reset --hard"
580 which is a synonym for "git reset --hard HEAD" clears the mess
581 from the index file and the working tree.
582 </p>
583 </li>
584 <li>
586 Merge a topic branch into the current branch, which resulted
587 in a fast-forward.
588 </p>
589 </li>
590 <li>
592 But you decided that the topic branch is not ready for public
593 consumption yet. "pull" or "merge" always leaves the original
594 tip of the current branch in ORIG_HEAD, so resetting hard to it
595 brings your index file and the working tree back to that state,
596 and resets the tip of the branch to that commit.
597 </p>
598 </li>
599 </ol></div>
600 </dd>
601 <dt>
602 Undo a merge or pull inside a dirty work tree
603 </dt>
604 <dd>
605 <div class="listingblock">
606 <div class="content">
607 <pre><tt>$ git pull <b>(1)</b>
608 Auto-merging nitfol
609 Merge made by recursive.
610 nitfol | 20 +++++----
612 $ git reset --merge ORIG_HEAD <b>(2)</b></tt></pre>
613 </div></div>
614 <div class="colist"><ol>
615 <li>
617 Even if you may have local modifications in your
618 working tree, you can safely say "git pull" when you know
619 that the change in the other branch does not overlap with
620 them.
621 </p>
622 </li>
623 <li>
625 After inspecting the result of the merge, you may find
626 that the change in the other branch is unsatisfactory. Running
627 "git reset --hard ORIG_HEAD" will let you go back to where you
628 were, but it will discard your local changes, which you do not
629 want. "git reset --merge" keeps your local changes.
630 </p>
631 </li>
632 </ol></div>
633 </dd>
634 <dt>
635 Interrupted workflow
636 </dt>
637 <dd>
638 <div class="para"><p>Suppose you are interrupted by an urgent fix request while you
639 are in the middle of a large change. The files in your
640 working tree are not in any shape to be committed yet, but you
641 need to get to the other branch for a quick bugfix.</p></div>
642 <div class="listingblock">
643 <div class="content">
644 <pre><tt>$ git checkout feature ;# you were working in "feature" branch and
645 $ work work work ;# got interrupted
646 $ git commit -a -m "snapshot WIP" <b>(1)</b>
647 $ git checkout master
648 $ fix fix fix
649 $ git commit ;# commit with real log
650 $ git checkout feature
651 $ git reset --soft HEAD^ ;# go back to WIP state <b>(2)</b>
652 $ git reset <b>(3)</b></tt></pre>
653 </div></div>
654 <div class="colist"><ol>
655 <li>
657 This commit will get blown away so a throw-away log message is OK.
658 </p>
659 </li>
660 <li>
662 This removes the <em>WIP</em> commit from the commit history, and sets
663 your working tree to the state just before you made that snapshot.
664 </p>
665 </li>
666 <li>
668 At this point the index file still has all the WIP changes you
669 committed as <em>snapshot WIP</em>. This updates the index to show your
670 WIP files as uncommitted.
671 </p>
672 <div class="para"><p>See also <a href="git-stash.html">git-stash(1)</a>.</p></div>
673 </li>
674 </ol></div>
675 </dd>
676 <dt>
677 Reset a single file in the index
678 </dt>
679 <dd>
680 <div class="para"><p>Suppose you have added a file to your index, but later decide you do not
681 want to add it to your commit. You can remove the file from the index
682 while keeping your changes with git reset.</p></div>
683 <div class="listingblock">
684 <div class="content">
685 <pre><tt>$ git reset -- frotz.c <b>(1)</b>
686 $ git commit -m "Commit files in index" <b>(2)</b>
687 $ git add frotz.c <b>(3)</b></tt></pre>
688 </div></div>
689 <div class="colist"><ol>
690 <li>
692 This removes the file from the index while keeping it in the working
693 directory.
694 </p>
695 </li>
696 <li>
698 This commits all other changes in the index.
699 </p>
700 </li>
701 <li>
703 Adds the file to the index again.
704 </p>
705 </li>
706 </ol></div>
707 </dd>
708 </dl></div>
709 </div>
710 <h2 id="_author">Author</h2>
711 <div class="sectionbody">
712 <div class="para"><p>Written by Junio C Hamano &lt;gitster@pobox.com&gt; and Linus Torvalds &lt;torvalds@osdl.org&gt;</p></div>
713 </div>
714 <h2 id="_documentation">Documentation</h2>
715 <div class="sectionbody">
716 <div class="para"><p>Documentation by Junio C Hamano and the git-list &lt;git@vger.kernel.org&gt;.</p></div>
717 </div>
718 <h2 id="_git">GIT</h2>
719 <div class="sectionbody">
720 <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
721 </div>
722 <div id="footer">
723 <div id="footer-text">
724 Last updated 2010-01-10 19:52:59 UTC
725 </div>
726 </div>
727 </body>
728 </html>