Autogenerated HTML docs for v1.7.4-rc2-20-g8c0db6
[git/jnareb-git.git] / git-reset.html
blobfe831115ad25ca5de2016d7b9edfcfadf6e5d299
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.4.5" />
7 <title>git-reset(1)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
129 div.content { /* Block element content. */
130 padding: 0;
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
142 div.title + * {
143 margin-top: 0;
146 td div.title:first-child {
147 margin-top: 0.0em;
149 div.content div.title:first-child {
150 margin-top: 0.0em;
152 div.content + div.title {
153 margin-top: 0.0em;
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
181 div.verseblock > div.content {
182 white-space: pre;
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
225 dd > *:first-child {
226 margin-top: 0.1em;
229 ul, ol {
230 list-style-position: outside;
232 ol.arabic {
233 list-style-type: decimal;
235 ol.loweralpha {
236 list-style-type: lower-alpha;
238 ol.upperalpha {
239 list-style-type: upper-alpha;
241 ol.lowerroman {
242 list-style-type: lower-roman;
244 ol.upperroman {
245 list-style-type: upper-roman;
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
255 div.tableblock > table {
256 border: 3px solid #527bbd;
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
262 tfoot {
263 font-weight: bold;
265 td > div.verse {
266 white-space: pre;
268 p.table {
269 margin-top: 0;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
289 div.hdlist tr {
290 padding-bottom: 15px;
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
301 td.hdlist2 {
302 vertical-align: top;
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
309 .comment {
310 background: yellow;
313 @media print {
314 div#footer-badges { display: none; }
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
342 /* Overrides for manpage documents */
343 h1 {
344 padding-top: 0.5em;
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver;
347 border-bottom: 2px solid silver;
349 h2 {
350 border-style: none;
352 div.sectionbody {
353 margin-left: 5%;
356 @media print {
357 div#toc { display: none; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div.sidebar-content {
363 background: #ffffee;
364 border: 1px solid silver;
365 padding: 0.5em;
367 div.sidebar-title, div.image-title {
368 color: #527bbd;
369 font-family: sans-serif;
370 font-weight: bold;
371 margin-top: 0.0em;
372 margin-bottom: 0.5em;
375 div.listingblock div.content {
376 border: 1px solid silver;
377 background: #f4f4f4;
378 padding: 0.5em;
381 div.quoteblock-attribution {
382 padding-top: 0.5em;
383 text-align: right;
386 div.verseblock-content {
387 white-space: pre;
389 div.verseblock-attribution {
390 padding-top: 0.75em;
391 text-align: left;
394 div.exampleblock-content {
395 border-left: 2px solid silver;
396 padding-left: 0.5em;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc a:visited { color: blue; }
401 </style>
402 </head>
403 <body>
404 <div id="header">
405 <h1>
406 git-reset(1) Manual Page
407 </h1>
408 <h2>NAME</h2>
409 <div class="sectionbody">
410 <p>git-reset -
411 Reset current HEAD to the specified state
412 </p>
413 </div>
414 </div>
415 <h2 id="_synopsis">SYNOPSIS</h2>
416 <div class="sectionbody">
417 <div class="verseblock">
418 <div class="verseblock-content"><em>git reset</em> [-q] [&lt;commit&gt;] [--] &lt;paths&gt;&#8230;
419 <em>git reset</em> --patch [&lt;commit&gt;] [--] [&lt;paths&gt;&#8230;]
420 <em>git reset</em> [--soft | --mixed | --hard | --merge | --keep] [-q] [&lt;commit&gt;]</div>
421 <div class="verseblock-attribution">
422 </div></div>
423 </div>
424 <h2 id="_description">DESCRIPTION</h2>
425 <div class="sectionbody">
426 <div class="paragraph"><p>In the first and second form, copy entries from &lt;commit&gt; to the index.
427 In the third form, set the current branch head (HEAD) to &lt;commit&gt;, optionally
428 modifying index and working tree to match. The &lt;commit&gt; defaults to HEAD
429 in all forms.</p></div>
430 <div class="dlist"><dl>
431 <dt class="hdlist1">
432 <em>git reset</em> [-q] [&lt;commit&gt;] [--] &lt;paths&gt;&#8230;
433 </dt>
434 <dd>
436 This form resets the index entries for all &lt;paths&gt; to their
437 state at &lt;commit&gt;. (It does not affect the working tree, nor
438 the current branch.)
439 </p>
440 <div class="paragraph"><p>This means that <tt>git reset &lt;paths&gt;</tt> is the opposite of <tt>git add
441 &lt;paths&gt;</tt>.</p></div>
442 <div class="paragraph"><p>After running <tt>git reset &lt;paths&gt;</tt> to update the index entry, you can
443 use <a href="git-checkout.html">git-checkout(1)</a> to check the contents out of the index to
444 the working tree.
445 Alternatively, using <a href="git-checkout.html">git-checkout(1)</a> and specifying a commit, you
446 can copy the contents of a path out of a commit to the index and to the
447 working tree in one go.</p></div>
448 </dd>
449 <dt class="hdlist1">
450 <em>git reset</em> --patch|-p [&lt;commit&gt;] [--] [&lt;paths&gt;&#8230;]
451 </dt>
452 <dd>
454 Interactively select hunks in the difference between the index
455 and &lt;commit&gt; (defaults to HEAD). The chosen hunks are applied
456 in reverse to the index.
457 </p>
458 <div class="paragraph"><p>This means that <tt>git reset -p</tt> is the opposite of <tt>git add -p</tt> (see
459 <a href="git-add.html">git-add(1)</a>).</p></div>
460 </dd>
461 <dt class="hdlist1">
462 <em>git reset</em> [--&lt;mode&gt;] [&lt;commit&gt;]
463 </dt>
464 <dd>
466 This form resets the current branch head to &lt;commit&gt; and
467 possibly updates the index (resetting it to the tree of &lt;commit&gt;) and
468 the working tree depending on &lt;mode&gt;, which
469 must be one of the following:
470 </p>
471 <div class="dlist"><dl>
472 <dt class="hdlist1">
473 --soft
474 </dt>
475 <dd>
477 Does not touch the index file nor the working tree at all (but
478 resets the head to &lt;commit&gt;, just like all modes do). This leaves
479 all your changed files "Changes to be committed", as <em>git status</em>
480 would put it.
481 </p>
482 </dd>
483 <dt class="hdlist1">
484 --mixed
485 </dt>
486 <dd>
488 Resets the index but not the working tree (i.e., the changed files
489 are preserved but not marked for commit) and reports what has not
490 been updated. This is the default action.
491 </p>
492 </dd>
493 <dt class="hdlist1">
494 --hard
495 </dt>
496 <dd>
498 Resets the index and working tree. Any changes to tracked files in the
499 working tree since &lt;commit&gt; are discarded.
500 </p>
501 </dd>
502 <dt class="hdlist1">
503 --merge
504 </dt>
505 <dd>
507 Resets the index and updates the files in the working tree that are
508 different between &lt;commit&gt; and HEAD, but keeps those which are
509 different between the index and working tree (i.e. which have changes
510 which have not been added).
511 If a file that is different between &lt;commit&gt; and the index has unstaged
512 changes, reset is aborted.
513 </p>
514 <div class="paragraph"><p>In other words, --merge does something like a <em>git read-tree -u -m &lt;commit&gt;</em>,
515 but carries forward unmerged index entries.</p></div>
516 </dd>
517 <dt class="hdlist1">
518 --keep
519 </dt>
520 <dd>
522 Resets index entries and updates files in the working tree that are
523 different between &lt;commit&gt; and HEAD.
524 If a file that is different between &lt;commit&gt; and HEAD has local changes,
525 reset is aborted.
526 </p>
527 </dd>
528 </dl></div>
529 </dd>
530 </dl></div>
531 <div class="paragraph"><p>If you want to undo a commit other than the latest on a branch,
532 <a href="git-revert.html">git-revert(1)</a> is your friend.</p></div>
533 </div>
534 <h2 id="_options">OPTIONS</h2>
535 <div class="sectionbody">
536 <div class="dlist"><dl>
537 <dt class="hdlist1">
539 </dt>
540 <dt class="hdlist1">
541 --quiet
542 </dt>
543 <dd>
545 Be quiet, only report errors.
546 </p>
547 </dd>
548 </dl></div>
549 </div>
550 <h2 id="_examples">EXAMPLES</h2>
551 <div class="sectionbody">
552 <div class="dlist"><dl>
553 <dt class="hdlist1">
554 Undo add
555 </dt>
556 <dd>
557 <div class="listingblock">
558 <div class="content">
559 <pre><tt>$ edit <b>&lt;1&gt;</b>
560 $ git add frotz.c filfre.c
561 $ mailx <b>&lt;2&gt;</b>
562 $ git reset <b>&lt;3&gt;</b>
563 $ git pull git://info.example.com/ nitfol <b>&lt;4&gt;</b></tt></pre>
564 </div></div>
565 <div class="colist arabic"><ol>
566 <li>
568 You are happily working on something, and find the changes
569 in these files are in good order. You do not want to see them
570 when you run "git diff", because you plan to work on other files
571 and changes with these files are distracting.
572 </p>
573 </li>
574 <li>
576 Somebody asks you to pull, and the changes sounds worthy of merging.
577 </p>
578 </li>
579 <li>
581 However, you already dirtied the index (i.e. your index does
582 not match the HEAD commit). But you know the pull you are going
583 to make does not affect frotz.c nor filfre.c, so you revert the
584 index changes for these two files. Your changes in working tree
585 remain there.
586 </p>
587 </li>
588 <li>
590 Then you can pull and merge, leaving frotz.c and filfre.c
591 changes still in the working tree.
592 </p>
593 </li>
594 </ol></div>
595 </dd>
596 <dt class="hdlist1">
597 Undo a commit and redo
598 </dt>
599 <dd>
600 <div class="listingblock">
601 <div class="content">
602 <pre><tt>$ git commit ...
603 $ git reset --soft HEAD^ <b>&lt;1&gt;</b>
604 $ edit <b>&lt;2&gt;</b>
605 $ git commit -a -c ORIG_HEAD <b>&lt;3&gt;</b></tt></pre>
606 </div></div>
607 <div class="colist arabic"><ol>
608 <li>
610 This is most often done when you remembered what you
611 just committed is incomplete, or you misspelled your commit
612 message, or both. Leaves working tree as it was before "reset".
613 </p>
614 </li>
615 <li>
617 Make corrections to working tree files.
618 </p>
619 </li>
620 <li>
622 "reset" copies the old head to .git/ORIG_HEAD; redo the
623 commit by starting with its log message. If you do not need to
624 edit the message further, you can give -C option instead.
625 </p>
626 <div class="paragraph"><p>See also the --amend option to <a href="git-commit.html">git-commit(1)</a>.</p></div>
627 </li>
628 </ol></div>
629 </dd>
630 <dt class="hdlist1">
631 Undo a commit, making it a topic branch
632 </dt>
633 <dd>
634 <div class="listingblock">
635 <div class="content">
636 <pre><tt>$ git branch topic/wip <b>&lt;1&gt;</b>
637 $ git reset --hard HEAD~3 <b>&lt;2&gt;</b>
638 $ git checkout topic/wip <b>&lt;3&gt;</b></tt></pre>
639 </div></div>
640 <div class="colist arabic"><ol>
641 <li>
643 You have made some commits, but realize they were premature
644 to be in the "master" branch. You want to continue polishing
645 them in a topic branch, so create "topic/wip" branch off of the
646 current HEAD.
647 </p>
648 </li>
649 <li>
651 Rewind the master branch to get rid of those three commits.
652 </p>
653 </li>
654 <li>
656 Switch to "topic/wip" branch and keep working.
657 </p>
658 </li>
659 </ol></div>
660 </dd>
661 <dt class="hdlist1">
662 Undo commits permanently
663 </dt>
664 <dd>
665 <div class="listingblock">
666 <div class="content">
667 <pre><tt>$ git commit ...
668 $ git reset --hard HEAD~3 <b>&lt;1&gt;</b></tt></pre>
669 </div></div>
670 <div class="colist arabic"><ol>
671 <li>
673 The last three commits (HEAD, HEAD^, and HEAD~2) were bad
674 and you do not want to ever see them again. Do <strong>not</strong> do this if
675 you have already given these commits to somebody else. (See the
676 "RECOVERING FROM UPSTREAM REBASE" section in <a href="git-rebase.html">git-rebase(1)</a> for
677 the implications of doing so.)
678 </p>
679 </li>
680 </ol></div>
681 </dd>
682 <dt class="hdlist1">
683 Undo a merge or pull
684 </dt>
685 <dd>
686 <div class="listingblock">
687 <div class="content">
688 <pre><tt>$ git pull <b>&lt;1&gt;</b>
689 Auto-merging nitfol
690 CONFLICT (content): Merge conflict in nitfol
691 Automatic merge failed; fix conflicts and then commit the result.
692 $ git reset --hard <b>&lt;2&gt;</b>
693 $ git pull . topic/branch <b>&lt;3&gt;</b>
694 Updating from 41223... to 13134...
695 Fast-forward
696 $ git reset --hard ORIG_HEAD <b>&lt;4&gt;</b></tt></pre>
697 </div></div>
698 <div class="colist arabic"><ol>
699 <li>
701 Try to update from the upstream resulted in a lot of
702 conflicts; you were not ready to spend a lot of time merging
703 right now, so you decide to do that later.
704 </p>
705 </li>
706 <li>
708 "pull" has not made merge commit, so "git reset --hard"
709 which is a synonym for "git reset --hard HEAD" clears the mess
710 from the index file and the working tree.
711 </p>
712 </li>
713 <li>
715 Merge a topic branch into the current branch, which resulted
716 in a fast-forward.
717 </p>
718 </li>
719 <li>
721 But you decided that the topic branch is not ready for public
722 consumption yet. "pull" or "merge" always leaves the original
723 tip of the current branch in ORIG_HEAD, so resetting hard to it
724 brings your index file and the working tree back to that state,
725 and resets the tip of the branch to that commit.
726 </p>
727 </li>
728 </ol></div>
729 </dd>
730 <dt class="hdlist1">
731 Undo a merge or pull inside a dirty working tree
732 </dt>
733 <dd>
734 <div class="listingblock">
735 <div class="content">
736 <pre><tt>$ git pull <b>&lt;1&gt;</b>
737 Auto-merging nitfol
738 Merge made by recursive.
739 nitfol | 20 +++++----
741 $ git reset --merge ORIG_HEAD <b>&lt;2&gt;</b></tt></pre>
742 </div></div>
743 <div class="colist arabic"><ol>
744 <li>
746 Even if you may have local modifications in your
747 working tree, you can safely say "git pull" when you know
748 that the change in the other branch does not overlap with
749 them.
750 </p>
751 </li>
752 <li>
754 After inspecting the result of the merge, you may find
755 that the change in the other branch is unsatisfactory. Running
756 "git reset --hard ORIG_HEAD" will let you go back to where you
757 were, but it will discard your local changes, which you do not
758 want. "git reset --merge" keeps your local changes.
759 </p>
760 </li>
761 </ol></div>
762 </dd>
763 <dt class="hdlist1">
764 Interrupted workflow
765 </dt>
766 <dd>
767 <div class="paragraph"><p>Suppose you are interrupted by an urgent fix request while you
768 are in the middle of a large change. The files in your
769 working tree are not in any shape to be committed yet, but you
770 need to get to the other branch for a quick bugfix.</p></div>
771 <div class="listingblock">
772 <div class="content">
773 <pre><tt>$ git checkout feature ;# you were working in "feature" branch and
774 $ work work work ;# got interrupted
775 $ git commit -a -m "snapshot WIP" <b>&lt;1&gt;</b>
776 $ git checkout master
777 $ fix fix fix
778 $ git commit ;# commit with real log
779 $ git checkout feature
780 $ git reset --soft HEAD^ ;# go back to WIP state <b>&lt;2&gt;</b>
781 $ git reset <b>&lt;3&gt;</b></tt></pre>
782 </div></div>
783 <div class="colist arabic"><ol>
784 <li>
786 This commit will get blown away so a throw-away log message is OK.
787 </p>
788 </li>
789 <li>
791 This removes the <em>WIP</em> commit from the commit history, and sets
792 your working tree to the state just before you made that snapshot.
793 </p>
794 </li>
795 <li>
797 At this point the index file still has all the WIP changes you
798 committed as <em>snapshot WIP</em>. This updates the index to show your
799 WIP files as uncommitted.
800 </p>
801 <div class="paragraph"><p>See also <a href="git-stash.html">git-stash(1)</a>.</p></div>
802 </li>
803 </ol></div>
804 </dd>
805 <dt class="hdlist1">
806 Reset a single file in the index
807 </dt>
808 <dd>
809 <div class="paragraph"><p>Suppose you have added a file to your index, but later decide you do not
810 want to add it to your commit. You can remove the file from the index
811 while keeping your changes with git reset.</p></div>
812 <div class="listingblock">
813 <div class="content">
814 <pre><tt>$ git reset -- frotz.c <b>&lt;1&gt;</b>
815 $ git commit -m "Commit files in index" <b>&lt;2&gt;</b>
816 $ git add frotz.c <b>&lt;3&gt;</b></tt></pre>
817 </div></div>
818 <div class="colist arabic"><ol>
819 <li>
821 This removes the file from the index while keeping it in the working
822 directory.
823 </p>
824 </li>
825 <li>
827 This commits all other changes in the index.
828 </p>
829 </li>
830 <li>
832 Adds the file to the index again.
833 </p>
834 </li>
835 </ol></div>
836 </dd>
837 <dt class="hdlist1">
838 Keep changes in working tree while discarding some previous commits
839 </dt>
840 <dd>
841 <div class="paragraph"><p>Suppose you are working on something and you commit it, and then you
842 continue working a bit more, but now you think that what you have in
843 your working tree should be in another branch that has nothing to do
844 with what you committed previously. You can start a new branch and
845 reset it while keeping the changes in your working tree.</p></div>
846 <div class="listingblock">
847 <div class="content">
848 <pre><tt>$ git tag start
849 $ git checkout -b branch1
850 $ edit
851 $ git commit ... <b>&lt;1&gt;</b>
852 $ edit
853 $ git checkout -b branch2 <b>&lt;2&gt;</b>
854 $ git reset --keep start <b>&lt;3&gt;</b></tt></pre>
855 </div></div>
856 <div class="colist arabic"><ol>
857 <li>
859 This commits your first edits in branch1.
860 </p>
861 </li>
862 <li>
864 In the ideal world, you could have realized that the earlier
865 commit did not belong to the new topic when you created and switched
866 to branch2 (i.e. "git checkout -b branch2 start"), but nobody is
867 perfect.
868 </p>
869 </li>
870 <li>
872 But you can use "reset --keep" to remove the unwanted commit after
873 you switched to "branch2".
874 </p>
875 </li>
876 </ol></div>
877 </dd>
878 </dl></div>
879 </div>
880 <h2 id="_discussion">DISCUSSION</h2>
881 <div class="sectionbody">
882 <div class="paragraph"><p>The tables below show what happens when running:</p></div>
883 <div class="listingblock">
884 <div class="content">
885 <pre><tt>git reset --option target</tt></pre>
886 </div></div>
887 <div class="paragraph"><p>to reset the HEAD to another commit (<tt>target</tt>) with the different
888 reset options depending on the state of the files.</p></div>
889 <div class="paragraph"><p>In these tables, A, B, C and D are some different states of a
890 file. For example, the first line of the first table means that if a
891 file is in state A in the working tree, in state B in the index, in
892 state C in HEAD and in state D in the target, then "git reset --soft
893 target" will leave the file in the working tree in state A and in the
894 index in state B. It resets (i.e. moves) the HEAD (i.e. the tip of
895 the current branch, if you are on one) to "target" (which has the file
896 in state D).</p></div>
897 <div class="literalblock">
898 <div class="content">
899 <pre><tt>working index HEAD target working index HEAD
900 ----------------------------------------------------
901 A B C D --soft A B D
902 --mixed A D D
903 --hard D D D
904 --merge (disallowed)
905 --keep (disallowed)</tt></pre>
906 </div></div>
907 <div class="literalblock">
908 <div class="content">
909 <pre><tt>working index HEAD target working index HEAD
910 ----------------------------------------------------
911 A B C C --soft A B C
912 --mixed A C C
913 --hard C C C
914 --merge (disallowed)
915 --keep A C C</tt></pre>
916 </div></div>
917 <div class="literalblock">
918 <div class="content">
919 <pre><tt>working index HEAD target working index HEAD
920 ----------------------------------------------------
921 B B C D --soft B B D
922 --mixed B D D
923 --hard D D D
924 --merge D D D
925 --keep (disallowed)</tt></pre>
926 </div></div>
927 <div class="literalblock">
928 <div class="content">
929 <pre><tt>working index HEAD target working index HEAD
930 ----------------------------------------------------
931 B B C C --soft B B C
932 --mixed B C C
933 --hard C C C
934 --merge C C C
935 --keep B C C</tt></pre>
936 </div></div>
937 <div class="literalblock">
938 <div class="content">
939 <pre><tt>working index HEAD target working index HEAD
940 ----------------------------------------------------
941 B C C D --soft B C D
942 --mixed B D D
943 --hard D D D
944 --merge (disallowed)
945 --keep (disallowed)</tt></pre>
946 </div></div>
947 <div class="literalblock">
948 <div class="content">
949 <pre><tt>working index HEAD target working index HEAD
950 ----------------------------------------------------
951 B C C C --soft B C C
952 --mixed B C C
953 --hard C C C
954 --merge B C C
955 --keep B C C</tt></pre>
956 </div></div>
957 <div class="paragraph"><p>"reset --merge" is meant to be used when resetting out of a conflicted
958 merge. Any mergy operation guarantees that the working tree file that is
959 involved in the merge does not have local change wrt the index before
960 it starts, and that it writes the result out to the working tree. So if
961 we see some difference between the index and the target and also
962 between the index and the working tree, then it means that we are not
963 resetting out from a state that a mergy operation left after failing
964 with a conflict. That is why we disallow --merge option in this case.</p></div>
965 <div class="paragraph"><p>"reset --keep" is meant to be used when removing some of the last
966 commits in the current branch while keeping changes in the working
967 tree. If there could be conflicts between the changes in the commit we
968 want to remove and the changes in the working tree we want to keep,
969 the reset is disallowed. That&#8217;s why it is disallowed if there are both
970 changes between the working tree and HEAD, and between HEAD and the
971 target. To be safe, it is also disallowed when there are unmerged
972 entries.</p></div>
973 <div class="paragraph"><p>The following tables show what happens when there are unmerged
974 entries:</p></div>
975 <div class="literalblock">
976 <div class="content">
977 <pre><tt>working index HEAD target working index HEAD
978 ----------------------------------------------------
979 X U A B --soft (disallowed)
980 --mixed X B B
981 --hard B B B
982 --merge B B B
983 --keep (disallowed)</tt></pre>
984 </div></div>
985 <div class="literalblock">
986 <div class="content">
987 <pre><tt>working index HEAD target working index HEAD
988 ----------------------------------------------------
989 X U A A --soft (disallowed)
990 --mixed X A A
991 --hard A A A
992 --merge A A A
993 --keep (disallowed)</tt></pre>
994 </div></div>
995 <div class="paragraph"><p>X means any state and U means an unmerged index.</p></div>
996 </div>
997 <h2 id="_author">Author</h2>
998 <div class="sectionbody">
999 <div class="paragraph"><p>Written by Junio C Hamano &lt;<a href="mailto:gitster@pobox.com">gitster@pobox.com</a>&gt; and Linus Torvalds &lt;<a href="mailto:torvalds@osdl.org">torvalds@osdl.org</a>&gt;</p></div>
1000 </div>
1001 <h2 id="_documentation">Documentation</h2>
1002 <div class="sectionbody">
1003 <div class="paragraph"><p>Documentation by Junio C Hamano and the git-list &lt;<a href="mailto:git@vger.kernel.org">git@vger.kernel.org</a>&gt;.</p></div>
1004 </div>
1005 <h2 id="_git">GIT</h2>
1006 <div class="sectionbody">
1007 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1008 </div>
1009 <div id="footer">
1010 <div id="footer-text">
1011 Last updated 2011-01-22 00:51:44 UTC
1012 </div>
1013 </div>
1014 </body>
1015 </html>