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 [
<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> (see
459 <a href=
"git-add.html">git-add(
1)
</a>).
</p></div>
462 <em>git reset
</em> [--
<mode
>] [
<commit
>]
466 This form resets the current branch head to
<commit
> and
467 possibly updates the index (resetting it to the tree of
<commit
>) and
468 the working tree depending on
<mode
>, which
469 must be one of the following:
471 <div class=
"dlist"><dl>
477 Does not touch the index file nor the working tree at all (but
478 resets the head to
<commit
>, just like all modes do). This leaves
479 all your changed files
"Changes to be committed", as
<em>git status
</em>
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.
498 Resets the index and working tree. Any changes to tracked files in the
499 working tree since
<commit
> are discarded.
507 Resets the index and updates the files in the working tree that are
508 different between
<commit
> 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
<commit
> and the index has unstaged
512 changes, reset is aborted.
514 <div class=
"paragraph"><p>In other words, --merge does something like a
<em>git read-tree -u -m
<commit
></em>,
515 but carries forward unmerged index entries.
</p></div>
522 Resets index entries and updates files in the working tree that are
523 different between
<commit
> and HEAD.
524 If a file that is different between
<commit
> and HEAD has local changes,
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>
534 <h2 id=
"_options">OPTIONS
</h2>
535 <div class=
"sectionbody">
536 <div class=
"dlist"><dl>
545 Be quiet, only report errors.
550 <h2 id=
"_examples">EXAMPLES
</h2>
551 <div class=
"sectionbody">
552 <div class=
"dlist"><dl>
557 <div class=
"listingblock">
558 <div class=
"content">
559 <pre><tt>$ edit
<b><1></b>
560 $ git add frotz.c filfre.c
561 $ mailx
<b><2></b>
562 $ git reset
<b><3></b>
563 $ git pull git://info.example.com/ nitfol
<b><4></b></tt></pre>
565 <div class=
"colist arabic"><ol>
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.
576 Somebody asks you to pull, and the changes sounds worthy of merging.
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
590 Then you can pull and merge, leaving frotz.c and filfre.c
591 changes still in the working tree.
597 Undo a commit and redo
600 <div class=
"listingblock">
601 <div class=
"content">
602 <pre><tt>$ git commit ...
603 $ git reset --soft HEAD^
<b><1></b>
604 $ edit
<b><2></b>
605 $ git commit -a -c ORIG_HEAD
<b><3></b></tt></pre>
607 <div class=
"colist arabic"><ol>
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".
617 Make corrections to working tree files.
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.
626 <div class=
"paragraph"><p>See also the --amend option to
<a href=
"git-commit.html">git-commit(
1)
</a>.
</p></div>
631 Undo a commit, making it a topic branch
634 <div class=
"listingblock">
635 <div class=
"content">
636 <pre><tt>$ git branch topic/wip
<b><1></b>
637 $ git reset --hard HEAD~
3 <b><2></b>
638 $ git checkout topic/wip
<b><3></b></tt></pre>
640 <div class=
"colist arabic"><ol>
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
651 Rewind the master branch to get rid of those three commits.
656 Switch to
"topic/wip" branch and keep working.
662 Undo commits permanently
665 <div class=
"listingblock">
666 <div class=
"content">
667 <pre><tt>$ git commit ...
668 $ git reset --hard HEAD~
3 <b><1></b></tt></pre>
670 <div class=
"colist arabic"><ol>
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.)
686 <div class=
"listingblock">
687 <div class=
"content">
688 <pre><tt>$ git pull
<b><1></b>
690 CONFLICT (content): Merge conflict in nitfol
691 Automatic merge failed; fix conflicts and then commit the result.
692 $ git reset --hard
<b><2></b>
693 $ git pull . topic/branch
<b><3></b>
694 Updating from
41223... to
13134...
696 $ git reset --hard ORIG_HEAD
<b><4></b></tt></pre>
698 <div class=
"colist arabic"><ol>
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.
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.
715 Merge a topic branch into the current branch, which resulted
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.
731 Undo a merge or pull inside a dirty working tree
734 <div class=
"listingblock">
735 <div class=
"content">
736 <pre><tt>$ git pull
<b><1></b>
738 Merge made by recursive.
739 nitfol |
20 +++++----
741 $ git reset --merge ORIG_HEAD
<b><2></b></tt></pre>
743 <div class=
"colist arabic"><ol>
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
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.
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><1></b>
776 $ git checkout master
778 $ git commit ;# commit with real log
779 $ git checkout feature
780 $ git reset --soft HEAD^ ;# go back to WIP state
<b><2></b>
781 $ git reset
<b><3></b></tt></pre>
783 <div class=
"colist arabic"><ol>
786 This commit will get blown away so a throw-away log message is OK.
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.
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.
801 <div class=
"paragraph"><p>See also
<a href=
"git-stash.html">git-stash(
1)
</a>.
</p></div>
806 Reset a single file in the index
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><1></b>
815 $ git commit -m
"Commit files in index" <b><2></b>
816 $ git add frotz.c
<b><3></b></tt></pre>
818 <div class=
"colist arabic"><ol>
821 This removes the file from the index while keeping it in the working
827 This commits all other changes in the index.
832 Adds the file to the index again.
838 Keep changes in working tree while discarding some previous commits
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
851 $ git commit ...
<b><1></b>
853 $ git checkout -b branch2
<b><2></b>
854 $ git reset --keep start
<b><3></b></tt></pre>
856 <div class=
"colist arabic"><ol>
859 This commits your first edits in branch1.
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
872 But you can use
"reset --keep" to remove the unwanted commit after
873 you switched to
"branch2".
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>
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 ----------------------------------------------------
905 --keep (disallowed)
</tt></pre>
907 <div class=
"literalblock">
908 <div class=
"content">
909 <pre><tt>working index HEAD target working index HEAD
910 ----------------------------------------------------
915 --keep A C C
</tt></pre>
917 <div class=
"literalblock">
918 <div class=
"content">
919 <pre><tt>working index HEAD target working index HEAD
920 ----------------------------------------------------
925 --keep (disallowed)
</tt></pre>
927 <div class=
"literalblock">
928 <div class=
"content">
929 <pre><tt>working index HEAD target working index HEAD
930 ----------------------------------------------------
935 --keep B C C
</tt></pre>
937 <div class=
"literalblock">
938 <div class=
"content">
939 <pre><tt>working index HEAD target working index HEAD
940 ----------------------------------------------------
945 --keep (disallowed)
</tt></pre>
947 <div class=
"literalblock">
948 <div class=
"content">
949 <pre><tt>working index HEAD target working index HEAD
950 ----------------------------------------------------
955 --keep B C C
</tt></pre>
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
’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
973 <div class=
"paragraph"><p>The following tables show what happens when there are unmerged
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)
983 --keep (disallowed)
</tt></pre>
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)
993 --keep (disallowed)
</tt></pre>
995 <div class=
"paragraph"><p>X means any state and U means an unmerged index.
</p></div>
997 <h2 id=
"_author">Author
</h2>
998 <div class=
"sectionbody">
999 <div class=
"paragraph"><p>Written by Junio C Hamano
<<a href=
"mailto:gitster@pobox.com">gitster@pobox.com
</a>> and Linus Torvalds
<<a href=
"mailto:torvalds@osdl.org">torvalds@osdl.org
</a>></p></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
<<a href=
"mailto:git@vger.kernel.org">git@vger.kernel.org
</a>>.
</p></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>
1010 <div id=
"footer-text">
1011 Last updated
2011-
01-
22 00:
51:
44 UTC