Autogenerated HTML docs for v1.7.6-345-g5c2f8
[git/jnareb-git.git] / git-reset.html
blob0f2411410ed4da7cc23172151402748362dd630c
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|-p] [&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>, i.e.
459 you can use it to selectively reset hunks. See the &#8220;Interactive Mode&#8221;
460 section of <a href="git-add.html">git-add(1)</a> to learn how to operate the <tt>--patch</tt> mode.</p></div>
461 </dd>
462 <dt class="hdlist1">
463 <em>git reset</em> [--&lt;mode&gt;] [&lt;commit&gt;]
464 </dt>
465 <dd>
467 This form resets the current branch head to &lt;commit&gt; and
468 possibly updates the index (resetting it to the tree of &lt;commit&gt;) and
469 the working tree depending on &lt;mode&gt;, which
470 must be one of the following:
471 </p>
472 <div class="dlist"><dl>
473 <dt class="hdlist1">
474 --soft
475 </dt>
476 <dd>
478 Does not touch the index file nor the working tree at all (but
479 resets the head to &lt;commit&gt;, just like all modes do). This leaves
480 all your changed files "Changes to be committed", as <em>git status</em>
481 would put it.
482 </p>
483 </dd>
484 <dt class="hdlist1">
485 --mixed
486 </dt>
487 <dd>
489 Resets the index but not the working tree (i.e., the changed files
490 are preserved but not marked for commit) and reports what has not
491 been updated. This is the default action.
492 </p>
493 </dd>
494 <dt class="hdlist1">
495 --hard
496 </dt>
497 <dd>
499 Resets the index and working tree. Any changes to tracked files in the
500 working tree since &lt;commit&gt; are discarded.
501 </p>
502 </dd>
503 <dt class="hdlist1">
504 --merge
505 </dt>
506 <dd>
508 Resets the index and updates the files in the working tree that are
509 different between &lt;commit&gt; and HEAD, but keeps those which are
510 different between the index and working tree (i.e. which have changes
511 which have not been added).
512 If a file that is different between &lt;commit&gt; and the index has unstaged
513 changes, reset is aborted.
514 </p>
515 <div class="paragraph"><p>In other words, --merge does something like a <em>git read-tree -u -m &lt;commit&gt;</em>,
516 but carries forward unmerged index entries.</p></div>
517 </dd>
518 <dt class="hdlist1">
519 --keep
520 </dt>
521 <dd>
523 Resets index entries and updates files in the working tree that are
524 different between &lt;commit&gt; and HEAD.
525 If a file that is different between &lt;commit&gt; and HEAD has local changes,
526 reset is aborted.
527 </p>
528 </dd>
529 </dl></div>
530 </dd>
531 </dl></div>
532 <div class="paragraph"><p>If you want to undo a commit other than the latest on a branch,
533 <a href="git-revert.html">git-revert(1)</a> is your friend.</p></div>
534 </div>
535 <h2 id="_options">OPTIONS</h2>
536 <div class="sectionbody">
537 <div class="dlist"><dl>
538 <dt class="hdlist1">
540 </dt>
541 <dt class="hdlist1">
542 --quiet
543 </dt>
544 <dd>
546 Be quiet, only report errors.
547 </p>
548 </dd>
549 </dl></div>
550 </div>
551 <h2 id="_examples">EXAMPLES</h2>
552 <div class="sectionbody">
553 <div class="dlist"><dl>
554 <dt class="hdlist1">
555 Undo add
556 </dt>
557 <dd>
558 <div class="listingblock">
559 <div class="content">
560 <pre><tt>$ edit <b>&lt;1&gt;</b>
561 $ git add frotz.c filfre.c
562 $ mailx <b>&lt;2&gt;</b>
563 $ git reset <b>&lt;3&gt;</b>
564 $ git pull git://info.example.com/ nitfol <b>&lt;4&gt;</b></tt></pre>
565 </div></div>
566 <div class="colist arabic"><ol>
567 <li>
569 You are happily working on something, and find the changes
570 in these files are in good order. You do not want to see them
571 when you run "git diff", because you plan to work on other files
572 and changes with these files are distracting.
573 </p>
574 </li>
575 <li>
577 Somebody asks you to pull, and the changes sounds worthy of merging.
578 </p>
579 </li>
580 <li>
582 However, you already dirtied the index (i.e. your index does
583 not match the HEAD commit). But you know the pull you are going
584 to make does not affect frotz.c nor filfre.c, so you revert the
585 index changes for these two files. Your changes in working tree
586 remain there.
587 </p>
588 </li>
589 <li>
591 Then you can pull and merge, leaving frotz.c and filfre.c
592 changes still in the working tree.
593 </p>
594 </li>
595 </ol></div>
596 </dd>
597 <dt class="hdlist1">
598 Undo a commit and redo
599 </dt>
600 <dd>
601 <div class="listingblock">
602 <div class="content">
603 <pre><tt>$ git commit ...
604 $ git reset --soft HEAD^ <b>&lt;1&gt;</b>
605 $ edit <b>&lt;2&gt;</b>
606 $ git commit -a -c ORIG_HEAD <b>&lt;3&gt;</b></tt></pre>
607 </div></div>
608 <div class="colist arabic"><ol>
609 <li>
611 This is most often done when you remembered what you
612 just committed is incomplete, or you misspelled your commit
613 message, or both. Leaves working tree as it was before "reset".
614 </p>
615 </li>
616 <li>
618 Make corrections to working tree files.
619 </p>
620 </li>
621 <li>
623 "reset" copies the old head to .git/ORIG_HEAD; redo the
624 commit by starting with its log message. If you do not need to
625 edit the message further, you can give -C option instead.
626 </p>
627 <div class="paragraph"><p>See also the --amend option to <a href="git-commit.html">git-commit(1)</a>.</p></div>
628 </li>
629 </ol></div>
630 </dd>
631 <dt class="hdlist1">
632 Undo a commit, making it a topic branch
633 </dt>
634 <dd>
635 <div class="listingblock">
636 <div class="content">
637 <pre><tt>$ git branch topic/wip <b>&lt;1&gt;</b>
638 $ git reset --hard HEAD~3 <b>&lt;2&gt;</b>
639 $ git checkout topic/wip <b>&lt;3&gt;</b></tt></pre>
640 </div></div>
641 <div class="colist arabic"><ol>
642 <li>
644 You have made some commits, but realize they were premature
645 to be in the "master" branch. You want to continue polishing
646 them in a topic branch, so create "topic/wip" branch off of the
647 current HEAD.
648 </p>
649 </li>
650 <li>
652 Rewind the master branch to get rid of those three commits.
653 </p>
654 </li>
655 <li>
657 Switch to "topic/wip" branch and keep working.
658 </p>
659 </li>
660 </ol></div>
661 </dd>
662 <dt class="hdlist1">
663 Undo commits permanently
664 </dt>
665 <dd>
666 <div class="listingblock">
667 <div class="content">
668 <pre><tt>$ git commit ...
669 $ git reset --hard HEAD~3 <b>&lt;1&gt;</b></tt></pre>
670 </div></div>
671 <div class="colist arabic"><ol>
672 <li>
674 The last three commits (HEAD, HEAD^, and HEAD~2) were bad
675 and you do not want to ever see them again. Do <strong>not</strong> do this if
676 you have already given these commits to somebody else. (See the
677 "RECOVERING FROM UPSTREAM REBASE" section in <a href="git-rebase.html">git-rebase(1)</a> for
678 the implications of doing so.)
679 </p>
680 </li>
681 </ol></div>
682 </dd>
683 <dt class="hdlist1">
684 Undo a merge or pull
685 </dt>
686 <dd>
687 <div class="listingblock">
688 <div class="content">
689 <pre><tt>$ git pull <b>&lt;1&gt;</b>
690 Auto-merging nitfol
691 CONFLICT (content): Merge conflict in nitfol
692 Automatic merge failed; fix conflicts and then commit the result.
693 $ git reset --hard <b>&lt;2&gt;</b>
694 $ git pull . topic/branch <b>&lt;3&gt;</b>
695 Updating from 41223... to 13134...
696 Fast-forward
697 $ git reset --hard ORIG_HEAD <b>&lt;4&gt;</b></tt></pre>
698 </div></div>
699 <div class="colist arabic"><ol>
700 <li>
702 Try to update from the upstream resulted in a lot of
703 conflicts; you were not ready to spend a lot of time merging
704 right now, so you decide to do that later.
705 </p>
706 </li>
707 <li>
709 "pull" has not made merge commit, so "git reset --hard"
710 which is a synonym for "git reset --hard HEAD" clears the mess
711 from the index file and the working tree.
712 </p>
713 </li>
714 <li>
716 Merge a topic branch into the current branch, which resulted
717 in a fast-forward.
718 </p>
719 </li>
720 <li>
722 But you decided that the topic branch is not ready for public
723 consumption yet. "pull" or "merge" always leaves the original
724 tip of the current branch in ORIG_HEAD, so resetting hard to it
725 brings your index file and the working tree back to that state,
726 and resets the tip of the branch to that commit.
727 </p>
728 </li>
729 </ol></div>
730 </dd>
731 <dt class="hdlist1">
732 Undo a merge or pull inside a dirty working tree
733 </dt>
734 <dd>
735 <div class="listingblock">
736 <div class="content">
737 <pre><tt>$ git pull <b>&lt;1&gt;</b>
738 Auto-merging nitfol
739 Merge made by recursive.
740 nitfol | 20 +++++----
742 $ git reset --merge ORIG_HEAD <b>&lt;2&gt;</b></tt></pre>
743 </div></div>
744 <div class="colist arabic"><ol>
745 <li>
747 Even if you may have local modifications in your
748 working tree, you can safely say "git pull" when you know
749 that the change in the other branch does not overlap with
750 them.
751 </p>
752 </li>
753 <li>
755 After inspecting the result of the merge, you may find
756 that the change in the other branch is unsatisfactory. Running
757 "git reset --hard ORIG_HEAD" will let you go back to where you
758 were, but it will discard your local changes, which you do not
759 want. "git reset --merge" keeps your local changes.
760 </p>
761 </li>
762 </ol></div>
763 </dd>
764 <dt class="hdlist1">
765 Interrupted workflow
766 </dt>
767 <dd>
768 <div class="paragraph"><p>Suppose you are interrupted by an urgent fix request while you
769 are in the middle of a large change. The files in your
770 working tree are not in any shape to be committed yet, but you
771 need to get to the other branch for a quick bugfix.</p></div>
772 <div class="listingblock">
773 <div class="content">
774 <pre><tt>$ git checkout feature ;# you were working in "feature" branch and
775 $ work work work ;# got interrupted
776 $ git commit -a -m "snapshot WIP" <b>&lt;1&gt;</b>
777 $ git checkout master
778 $ fix fix fix
779 $ git commit ;# commit with real log
780 $ git checkout feature
781 $ git reset --soft HEAD^ ;# go back to WIP state <b>&lt;2&gt;</b>
782 $ git reset <b>&lt;3&gt;</b></tt></pre>
783 </div></div>
784 <div class="colist arabic"><ol>
785 <li>
787 This commit will get blown away so a throw-away log message is OK.
788 </p>
789 </li>
790 <li>
792 This removes the <em>WIP</em> commit from the commit history, and sets
793 your working tree to the state just before you made that snapshot.
794 </p>
795 </li>
796 <li>
798 At this point the index file still has all the WIP changes you
799 committed as <em>snapshot WIP</em>. This updates the index to show your
800 WIP files as uncommitted.
801 </p>
802 <div class="paragraph"><p>See also <a href="git-stash.html">git-stash(1)</a>.</p></div>
803 </li>
804 </ol></div>
805 </dd>
806 <dt class="hdlist1">
807 Reset a single file in the index
808 </dt>
809 <dd>
810 <div class="paragraph"><p>Suppose you have added a file to your index, but later decide you do not
811 want to add it to your commit. You can remove the file from the index
812 while keeping your changes with git reset.</p></div>
813 <div class="listingblock">
814 <div class="content">
815 <pre><tt>$ git reset -- frotz.c <b>&lt;1&gt;</b>
816 $ git commit -m "Commit files in index" <b>&lt;2&gt;</b>
817 $ git add frotz.c <b>&lt;3&gt;</b></tt></pre>
818 </div></div>
819 <div class="colist arabic"><ol>
820 <li>
822 This removes the file from the index while keeping it in the working
823 directory.
824 </p>
825 </li>
826 <li>
828 This commits all other changes in the index.
829 </p>
830 </li>
831 <li>
833 Adds the file to the index again.
834 </p>
835 </li>
836 </ol></div>
837 </dd>
838 <dt class="hdlist1">
839 Keep changes in working tree while discarding some previous commits
840 </dt>
841 <dd>
842 <div class="paragraph"><p>Suppose you are working on something and you commit it, and then you
843 continue working a bit more, but now you think that what you have in
844 your working tree should be in another branch that has nothing to do
845 with what you committed previously. You can start a new branch and
846 reset it while keeping the changes in your working tree.</p></div>
847 <div class="listingblock">
848 <div class="content">
849 <pre><tt>$ git tag start
850 $ git checkout -b branch1
851 $ edit
852 $ git commit ... <b>&lt;1&gt;</b>
853 $ edit
854 $ git checkout -b branch2 <b>&lt;2&gt;</b>
855 $ git reset --keep start <b>&lt;3&gt;</b></tt></pre>
856 </div></div>
857 <div class="colist arabic"><ol>
858 <li>
860 This commits your first edits in branch1.
861 </p>
862 </li>
863 <li>
865 In the ideal world, you could have realized that the earlier
866 commit did not belong to the new topic when you created and switched
867 to branch2 (i.e. "git checkout -b branch2 start"), but nobody is
868 perfect.
869 </p>
870 </li>
871 <li>
873 But you can use "reset --keep" to remove the unwanted commit after
874 you switched to "branch2".
875 </p>
876 </li>
877 </ol></div>
878 </dd>
879 </dl></div>
880 </div>
881 <h2 id="_discussion">DISCUSSION</h2>
882 <div class="sectionbody">
883 <div class="paragraph"><p>The tables below show what happens when running:</p></div>
884 <div class="listingblock">
885 <div class="content">
886 <pre><tt>git reset --option target</tt></pre>
887 </div></div>
888 <div class="paragraph"><p>to reset the HEAD to another commit (<tt>target</tt>) with the different
889 reset options depending on the state of the files.</p></div>
890 <div class="paragraph"><p>In these tables, A, B, C and D are some different states of a
891 file. For example, the first line of the first table means that if a
892 file is in state A in the working tree, in state B in the index, in
893 state C in HEAD and in state D in the target, then "git reset --soft
894 target" will leave the file in the working tree in state A and in the
895 index in state B. It resets (i.e. moves) the HEAD (i.e. the tip of
896 the current branch, if you are on one) to "target" (which has the file
897 in state D).</p></div>
898 <div class="literalblock">
899 <div class="content">
900 <pre><tt>working index HEAD target working index HEAD
901 ----------------------------------------------------
902 A B C D --soft A B D
903 --mixed A D D
904 --hard D D D
905 --merge (disallowed)
906 --keep (disallowed)</tt></pre>
907 </div></div>
908 <div class="literalblock">
909 <div class="content">
910 <pre><tt>working index HEAD target working index HEAD
911 ----------------------------------------------------
912 A B C C --soft A B C
913 --mixed A C C
914 --hard C C C
915 --merge (disallowed)
916 --keep A C C</tt></pre>
917 </div></div>
918 <div class="literalblock">
919 <div class="content">
920 <pre><tt>working index HEAD target working index HEAD
921 ----------------------------------------------------
922 B B C D --soft B B D
923 --mixed B D D
924 --hard D D D
925 --merge D D D
926 --keep (disallowed)</tt></pre>
927 </div></div>
928 <div class="literalblock">
929 <div class="content">
930 <pre><tt>working index HEAD target working index HEAD
931 ----------------------------------------------------
932 B B C C --soft B B C
933 --mixed B C C
934 --hard C C C
935 --merge C C C
936 --keep B C C</tt></pre>
937 </div></div>
938 <div class="literalblock">
939 <div class="content">
940 <pre><tt>working index HEAD target working index HEAD
941 ----------------------------------------------------
942 B C C D --soft B C D
943 --mixed B D D
944 --hard D D D
945 --merge (disallowed)
946 --keep (disallowed)</tt></pre>
947 </div></div>
948 <div class="literalblock">
949 <div class="content">
950 <pre><tt>working index HEAD target working index HEAD
951 ----------------------------------------------------
952 B C C C --soft B C C
953 --mixed B C C
954 --hard C C C
955 --merge B C C
956 --keep B C C</tt></pre>
957 </div></div>
958 <div class="paragraph"><p>"reset --merge" is meant to be used when resetting out of a conflicted
959 merge. Any mergy operation guarantees that the working tree file that is
960 involved in the merge does not have local change wrt the index before
961 it starts, and that it writes the result out to the working tree. So if
962 we see some difference between the index and the target and also
963 between the index and the working tree, then it means that we are not
964 resetting out from a state that a mergy operation left after failing
965 with a conflict. That is why we disallow --merge option in this case.</p></div>
966 <div class="paragraph"><p>"reset --keep" is meant to be used when removing some of the last
967 commits in the current branch while keeping changes in the working
968 tree. If there could be conflicts between the changes in the commit we
969 want to remove and the changes in the working tree we want to keep,
970 the reset is disallowed. That&#8217;s why it is disallowed if there are both
971 changes between the working tree and HEAD, and between HEAD and the
972 target. To be safe, it is also disallowed when there are unmerged
973 entries.</p></div>
974 <div class="paragraph"><p>The following tables show what happens when there are unmerged
975 entries:</p></div>
976 <div class="literalblock">
977 <div class="content">
978 <pre><tt>working index HEAD target working index HEAD
979 ----------------------------------------------------
980 X U A B --soft (disallowed)
981 --mixed X B B
982 --hard B B B
983 --merge B B B
984 --keep (disallowed)</tt></pre>
985 </div></div>
986 <div class="literalblock">
987 <div class="content">
988 <pre><tt>working index HEAD target working index HEAD
989 ----------------------------------------------------
990 X U A A --soft (disallowed)
991 --mixed X A A
992 --hard A A A
993 --merge A A A
994 --keep (disallowed)</tt></pre>
995 </div></div>
996 <div class="paragraph"><p>X means any state and U means an unmerged index.</p></div>
997 </div>
998 <h2 id="_git">GIT</h2>
999 <div class="sectionbody">
1000 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1001 </div>
1002 <div id="footer">
1003 <div id="footer-text">
1004 Last updated 2011-05-11 20:08:54 UTC
1005 </div>
1006 </div>
1007 </body>
1008 </html>