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">
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">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.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
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.5em;
129 div
.content
{ /* Block element content. */
133 /* Block element titles. */
134 div
.title
, caption
.title
{
136 font-family: sans-serif
;
140 margin-bottom: 0.5em;
146 td div
.title:first-child
{
149 div
.content div
.title:first-child
{
152 div
.content
+ div
.title
{
156 div
.sidebarblock
> div
.content
{
158 border: 1px solid silver
;
162 div
.listingblock
> div
.content
{
163 border: 1px solid silver
;
172 div
.quoteblock
> div
.attribution
{
181 div
.verseblock
> div
.content
{
184 div
.verseblock
> div
.attribution
{
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div
.verseblock
+ div
.attribution
{
193 div
.admonitionblock
.icon
{
197 text-decoration: underline
;
199 padding-right: 0.5em;
201 div
.admonitionblock td
.content
{
203 border-left: 2px solid silver
;
206 div
.exampleblock
> div
.content
{
207 border-left: 2px solid silver
;
211 div
.imageblock div
.content
{ padding-left: 0; }
212 span
.image img
{ border-style: none
; }
213 a
.image:visited
{ color: white
; }
217 margin-bottom: 0.8em;
230 list-style-position: outside
;
233 list-style-type: decimal
;
236 list-style-type: lower-alpha
;
239 list-style-type: upper-alpha
;
242 list-style-type: lower-roman
;
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
{
252 margin-bottom: 0.1em;
255 div
.tableblock
> table
{
256 border: 3px solid
#527bbd;
259 font-family: sans-serif
;
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div
.tableblock
> table
[frame
="void"] {
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
;
287 margin-bottom: 0.8em;
290 padding-bottom: 15px;
292 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
298 padding-right: 0.8em;
304 div
.hdlist
.compact tr
{
314 div#footer-badges
{ display: none
; }
319 font-family: sans-serif
;
323 margin-bottom: 0.1em;
326 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
342 /* Overrides for manpage documents */
345 padding-bottom: 0.5em;
346 border-top: 2px solid silver
;
347 border-bottom: 2px solid silver
;
357 div#toc
{ display: none
; }
360 /* Workarounds for IE6's broken and incomplete CSS2. */
362 div
.sidebar-content
{
364 border: 1px solid silver
;
367 div
.sidebar-title
, div
.image-title
{
369 font-family: sans-serif
;
372 margin-bottom: 0.5em;
375 div
.listingblock div
.content
{
376 border: 1px solid silver
;
381 div
.quoteblock-attribution
{
386 div
.verseblock-content
{
389 div
.verseblock-attribution
{
394 div
.exampleblock-content
{
395 border-left: 2px solid silver
;
399 /* IE6 sets dynamically generated links as visited. */
400 div#toc
a:visited
{ color: blue
; }
406 git-reset(
1) Manual Page
409 <div class=
"sectionbody">
411 Reset current HEAD to the specified state
415 <h2 id=
"_synopsis">SYNOPSIS
</h2>
416 <div class=
"sectionbody">
417 <div class=
"verseblock">
418 <div class=
"verseblock-content"><em>git reset
</em> [-q] [
<commit
>] [--]
<paths
>…
419 <em>git reset
</em> [--patch|-p] [
<commit
>] [--] [
<paths
>…]
420 <em>git reset
</em> [--soft | --mixed | --hard | --merge | --keep] [-q] [
<commit
>]
</div>
421 <div class=
"verseblock-attribution">
424 <h2 id=
"_description">DESCRIPTION
</h2>
425 <div class=
"sectionbody">
426 <div class=
"paragraph"><p>In the first and second form, copy entries from
<commit
> to the index.
427 In the third form, set the current branch head (HEAD) to
<commit
>, optionally
428 modifying index and working tree to match. The
<commit
> defaults to HEAD
429 in all forms.
</p></div>
430 <div class=
"dlist"><dl>
432 <em>git reset
</em> [-q] [
<commit
>] [--]
<paths
>…
436 This form resets the index entries for all
<paths
> to their
437 state at
<commit
>. (It does not affect the working tree, nor
440 <div class=
"paragraph"><p>This means that
<tt>git reset
<paths
></tt> is the opposite of
<tt>git add
441 <paths
></tt>.
</p></div>
442 <div class=
"paragraph"><p>After running
<tt>git reset
<paths
></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
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>
450 <em>git reset
</em> --patch|-p [
<commit
>] [--] [
<paths
>…]
454 Interactively select hunks in the difference between the index
455 and
<commit
> (defaults to HEAD). The chosen hunks are applied
456 in reverse to the index.
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
“Interactive Mode
”
460 section of
<a href=
"git-add.html">git-add(
1)
</a> to learn how to operate the
<tt>--patch
</tt> mode.
</p></div>
463 <em>git reset
</em> [--
<mode
>] [
<commit
>]
467 This form resets the current branch head to
<commit
> and
468 possibly updates the index (resetting it to the tree of
<commit
>) and
469 the working tree depending on
<mode
>, which
470 must be one of the following:
472 <div class=
"dlist"><dl>
478 Does not touch the index file nor the working tree at all (but
479 resets the head to
<commit
>, just like all modes do). This leaves
480 all your changed files
"Changes to be committed", as
<em>git status
</em>
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.
499 Resets the index and working tree. Any changes to tracked files in the
500 working tree since
<commit
> are discarded.
508 Resets the index and updates the files in the working tree that are
509 different between
<commit
> 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
<commit
> and the index has unstaged
513 changes, reset is aborted.
515 <div class=
"paragraph"><p>In other words, --merge does something like a
<em>git read-tree -u -m
<commit
></em>,
516 but carries forward unmerged index entries.
</p></div>
523 Resets index entries and updates files in the working tree that are
524 different between
<commit
> and HEAD.
525 If a file that is different between
<commit
> and HEAD has local changes,
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>
535 <h2 id=
"_options">OPTIONS
</h2>
536 <div class=
"sectionbody">
537 <div class=
"dlist"><dl>
546 Be quiet, only report errors.
551 <h2 id=
"_examples">EXAMPLES
</h2>
552 <div class=
"sectionbody">
553 <div class=
"dlist"><dl>
558 <div class=
"listingblock">
559 <div class=
"content">
560 <pre><tt>$ edit
<b><1></b>
561 $ git add frotz.c filfre.c
562 $ mailx
<b><2></b>
563 $ git reset
<b><3></b>
564 $ git pull git://info.example.com/ nitfol
<b><4></b></tt></pre>
566 <div class=
"colist arabic"><ol>
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.
577 Somebody asks you to pull, and the changes sounds worthy of merging.
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
591 Then you can pull and merge, leaving frotz.c and filfre.c
592 changes still in the working tree.
598 Undo a commit and redo
601 <div class=
"listingblock">
602 <div class=
"content">
603 <pre><tt>$ git commit ...
604 $ git reset --soft HEAD^
<b><1></b>
605 $ edit
<b><2></b>
606 $ git commit -a -c ORIG_HEAD
<b><3></b></tt></pre>
608 <div class=
"colist arabic"><ol>
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".
618 Make corrections to working tree files.
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.
627 <div class=
"paragraph"><p>See also the --amend option to
<a href=
"git-commit.html">git-commit(
1)
</a>.
</p></div>
632 Undo a commit, making it a topic branch
635 <div class=
"listingblock">
636 <div class=
"content">
637 <pre><tt>$ git branch topic/wip
<b><1></b>
638 $ git reset --hard HEAD~
3 <b><2></b>
639 $ git checkout topic/wip
<b><3></b></tt></pre>
641 <div class=
"colist arabic"><ol>
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
652 Rewind the master branch to get rid of those three commits.
657 Switch to
"topic/wip" branch and keep working.
663 Undo commits permanently
666 <div class=
"listingblock">
667 <div class=
"content">
668 <pre><tt>$ git commit ...
669 $ git reset --hard HEAD~
3 <b><1></b></tt></pre>
671 <div class=
"colist arabic"><ol>
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.)
687 <div class=
"listingblock">
688 <div class=
"content">
689 <pre><tt>$ git pull
<b><1></b>
691 CONFLICT (content): Merge conflict in nitfol
692 Automatic merge failed; fix conflicts and then commit the result.
693 $ git reset --hard
<b><2></b>
694 $ git pull . topic/branch
<b><3></b>
695 Updating from
41223... to
13134...
697 $ git reset --hard ORIG_HEAD
<b><4></b></tt></pre>
699 <div class=
"colist arabic"><ol>
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.
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.
716 Merge a topic branch into the current branch, which resulted
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.
732 Undo a merge or pull inside a dirty working tree
735 <div class=
"listingblock">
736 <div class=
"content">
737 <pre><tt>$ git pull
<b><1></b>
739 Merge made by recursive.
740 nitfol |
20 +++++----
742 $ git reset --merge ORIG_HEAD
<b><2></b></tt></pre>
744 <div class=
"colist arabic"><ol>
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
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.
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><1></b>
777 $ git checkout master
779 $ git commit ;# commit with real log
780 $ git checkout feature
781 $ git reset --soft HEAD^ ;# go back to WIP state
<b><2></b>
782 $ git reset
<b><3></b></tt></pre>
784 <div class=
"colist arabic"><ol>
787 This commit will get blown away so a throw-away log message is OK.
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.
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.
802 <div class=
"paragraph"><p>See also
<a href=
"git-stash.html">git-stash(
1)
</a>.
</p></div>
807 Reset a single file in the index
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><1></b>
816 $ git commit -m
"Commit files in index" <b><2></b>
817 $ git add frotz.c
<b><3></b></tt></pre>
819 <div class=
"colist arabic"><ol>
822 This removes the file from the index while keeping it in the working
828 This commits all other changes in the index.
833 Adds the file to the index again.
839 Keep changes in working tree while discarding some previous commits
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
852 $ git commit ...
<b><1></b>
854 $ git checkout -b branch2
<b><2></b>
855 $ git reset --keep start
<b><3></b></tt></pre>
857 <div class=
"colist arabic"><ol>
860 This commits your first edits in branch1.
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
873 But you can use
"reset --keep" to remove the unwanted commit after
874 you switched to
"branch2".
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>
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 ----------------------------------------------------
906 --keep (disallowed)
</tt></pre>
908 <div class=
"literalblock">
909 <div class=
"content">
910 <pre><tt>working index HEAD target working index HEAD
911 ----------------------------------------------------
916 --keep A C C
</tt></pre>
918 <div class=
"literalblock">
919 <div class=
"content">
920 <pre><tt>working index HEAD target working index HEAD
921 ----------------------------------------------------
926 --keep (disallowed)
</tt></pre>
928 <div class=
"literalblock">
929 <div class=
"content">
930 <pre><tt>working index HEAD target working index HEAD
931 ----------------------------------------------------
936 --keep B C C
</tt></pre>
938 <div class=
"literalblock">
939 <div class=
"content">
940 <pre><tt>working index HEAD target working index HEAD
941 ----------------------------------------------------
946 --keep (disallowed)
</tt></pre>
948 <div class=
"literalblock">
949 <div class=
"content">
950 <pre><tt>working index HEAD target working index HEAD
951 ----------------------------------------------------
956 --keep B C C
</tt></pre>
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
’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
974 <div class=
"paragraph"><p>The following tables show what happens when there are unmerged
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)
984 --keep (disallowed)
</tt></pre>
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)
994 --keep (disallowed)
</tt></pre>
996 <div class=
"paragraph"><p>X means any state and U means an unmerged index.
</p></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>
1003 <div id=
"footer-text">
1004 Last updated
2011-
05-
11 20:
08:
54 UTC