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.2.5" />
7 <style type=
"text/css">
9 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
11 border: 1px solid red;
16 margin: 1em 5% 1em 5%;
21 text-decoration: underline
;
39 h1
, h2
, h3
, h4
, h5
, h6
{
41 font-family: sans-serif
;
48 border-bottom: 2px solid silver
;
66 border: 1px solid silver
;
81 font-family: sans-serif
;
88 font-family: sans-serif
;
92 font-family: sans-serif
;
94 border-top: 2px solid silver
;
100 padding-bottom: 0.5em;
104 padding-bottom: 0.5em;
108 div
.tableblock
, div
.imageblock
, div
.exampleblock
, div
.verseblock
,
109 div
.quoteblock
, div
.literalblock
, div
.listingblock
, div
.sidebarblock
,
110 div
.admonitionblock
{
113 margin-bottom: 1.5em;
115 div
.admonitionblock
{
117 margin-bottom: 2.5em;
120 div
.content
{ /* Block element content. */
124 /* Block element titles. */
125 div
.title
, caption
.title
{
126 font-family: sans-serif
;
130 margin-bottom: 0.5em;
136 td div
.title:first-child
{
139 div
.content div
.title:first-child
{
142 div
.content
+ div
.title
{
146 div
.sidebarblock
> div
.content
{
148 border: 1px solid silver
;
155 div
.listingblock
> div
.content
{
156 border: 1px solid silver
;
161 div
.quoteblock
> div
.content
{
168 div
.verseblock
+ div
.attribution
{
172 div
.admonitionblock
.icon
{
176 text-decoration: underline
;
178 padding-right: 0.5em;
180 div
.admonitionblock td
.content
{
182 border-left: 2px solid silver
;
185 div
.exampleblock
> div
.content
{
186 border-left: 2px solid silver
;
190 div
.verseblock div
.content
{
194 div
.imageblock div
.content
{ padding-left: 0; }
195 div
.imageblock img
{ border: 1px solid silver
; }
196 span
.image img
{ border-style: none
; }
200 margin-bottom: 0.8em;
212 list-style-position: outside
;
215 list-style-type: lower-alpha
;
218 div
.tableblock
> table
{
219 border: 3px solid
#527bbd;
222 font-family: sans-serif
;
231 margin-bottom: 0.8em;
239 padding-right: 0.8em;
246 div#footer-badges
{ display: none
; }
251 font-family: sans-serif
;
255 margin-bottom: 0.1em;
258 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
274 include1::./stylesheets
/xhtml11-manpage
.css
[]
275 /* Workarounds for IE6's broken and incomplete CSS2. */
277 div
.sidebar-content
{
279 border: 1px solid silver
;
282 div
.sidebar-title
, div
.image-title
{
283 font-family: sans-serif
;
286 margin-bottom: 0.5em;
289 div
.listingblock div
.content
{
290 border: 1px solid silver
;
295 div
.quoteblock-content
{
299 div
.exampleblock-content
{
300 border-left: 2px solid silver
;
304 /* IE6 sets dynamically generated links as visited. */
305 div#toc
a:visited
{ color: blue
; }
307 <title>git-reset(
1)
</title>
312 git-reset(
1) Manual Page
315 <div class=
"sectionbody">
317 Reset current HEAD to the specified state
322 <div class=
"sectionbody">
323 <div class=
"verseblock">
324 <div class=
"content"><em>git reset
</em> [-q] [
<commit
>] [--]
<paths
>…
325 <em>git reset
</em> --patch [
<commit
>] [--] [
<paths
>…]
326 <em>git reset
</em> [--soft | --mixed | --hard | --merge | --keep] [-q] [
<commit
>]
</div></div>
328 <h2 id=
"_description">DESCRIPTION
</h2>
329 <div class=
"sectionbody">
330 <div class=
"para"><p>In the first and second form, copy entries from
<commit
> to the index.
331 In the third form, set the current branch to
<commit
>, optionally
332 modifying index and worktree to match. The
<commit
> defaults to HEAD
333 in all forms.
</p></div>
334 <div class=
"vlist"><dl>
336 <em>git reset
</em> [-q] [
<commit
>] [--]
<paths
>…
340 This form resets the index entries for all
<paths
> to their
341 state at the
<commit
>. (It does not affect the worktree, nor
344 <div class=
"para"><p>This means that
<tt>git reset
<paths
></tt> is the opposite of
<tt>git add
345 <paths
></tt>.
</p></div>
348 <em>git reset
</em> --patch|-p [
<commit
>] [--] [
<paths
>…]
352 Interactively select hunks in the difference between the index
353 and
<commit
> (defaults to HEAD). The chosen hunks are applied
354 in reverse to the index.
356 <div class=
"para"><p>This means that
<tt>git reset -p
</tt> is the opposite of
<tt>git add -p
</tt> (see
357 <a href=
"git-add.html">git-add(
1)
</a>).
</p></div>
360 <em>git reset
</em> [--
<mode
>] [
<commit
>]
364 This form points the current branch to
<commit
> and then
365 updates index and working tree according to
<mode
>, which must
366 be one of the following:
368 <div class=
"vlist"><dl>
374 Does not touch the index file nor the working tree at all, but
375 requires them to be in a good order. This leaves all your changed
376 files
"Changes to be committed", as
<em>git status
</em> would
385 Resets the index but not the working tree (i.e., the changed files
386 are preserved but not marked for commit) and reports what has not
387 been updated. This is the default action.
395 Matches the working tree and index to that of the tree being
396 switched to. Any changes to tracked files in the working tree
397 since
<commit
> are lost.
405 Resets the index to match the tree recorded by the named commit,
406 and updates the files that are different between the named commit
407 and the current commit in the working tree.
415 Reset the index to the given commit, keeping local changes in
416 the working tree since the current commit, while updating
417 working tree files without local changes to what appears in
418 the given commit. If a file that is different between the
419 current commit and the given commit has local changes, reset
426 <div class=
"para"><p>If you want to undo a commit other than the latest on a branch,
427 <a href=
"git-revert.html">git-revert(
1)
</a> is your friend.
</p></div>
429 <h2 id=
"_options">OPTIONS
</h2>
430 <div class=
"sectionbody">
431 <div class=
"vlist"><dl>
440 Be quiet, only report errors.
445 <h2 id=
"_examples">EXAMPLES
</h2>
446 <div class=
"sectionbody">
447 <div class=
"vlist"><dl>
452 <div class=
"listingblock">
453 <div class=
"content">
454 <pre><tt>$ edit
<b>(
1)
</b>
455 $ git add frotz.c filfre.c
457 $ git reset
<b>(
3)
</b>
458 $ git pull git://info.example.com/ nitfol
<b>(
4)
</b></tt></pre>
460 <div class=
"colist"><ol>
463 You are happily working on something, and find the changes
464 in these files are in good order. You do not want to see them
465 when you run
"git diff", because you plan to work on other files
466 and changes with these files are distracting.
471 Somebody asks you to pull, and the changes sounds worthy of merging.
476 However, you already dirtied the index (i.e. your index does
477 not match the HEAD commit). But you know the pull you are going
478 to make does not affect frotz.c nor filfre.c, so you revert the
479 index changes for these two files. Your changes in working tree
485 Then you can pull and merge, leaving frotz.c and filfre.c
486 changes still in the working tree.
492 Undo a commit and redo
495 <div class=
"listingblock">
496 <div class=
"content">
497 <pre><tt>$ git commit ...
498 $ git reset --soft HEAD^
<b>(
1)
</b>
500 $ git commit -a -c ORIG_HEAD
<b>(
3)
</b></tt></pre>
502 <div class=
"colist"><ol>
505 This is most often done when you remembered what you
506 just committed is incomplete, or you misspelled your commit
507 message, or both. Leaves working tree as it was before
"reset".
512 Make corrections to working tree files.
517 "reset" copies the old head to .git/ORIG_HEAD; redo the
518 commit by starting with its log message. If you do not need to
519 edit the message further, you can give -C option instead.
521 <div class=
"para"><p>See also the --amend option to
<a href=
"git-commit.html">git-commit(
1)
</a>.
</p></div>
526 Undo a commit, making it a topic branch
529 <div class=
"listingblock">
530 <div class=
"content">
531 <pre><tt>$ git branch topic/wip
<b>(
1)
</b>
532 $ git reset --hard HEAD~
3 <b>(
2)
</b>
533 $ git checkout topic/wip
<b>(
3)
</b></tt></pre>
535 <div class=
"colist"><ol>
538 You have made some commits, but realize they were premature
539 to be in the
"master" branch. You want to continue polishing
540 them in a topic branch, so create
"topic/wip" branch off of the
546 Rewind the master branch to get rid of those three commits.
551 Switch to
"topic/wip" branch and keep working.
557 Undo commits permanently
560 <div class=
"listingblock">
561 <div class=
"content">
562 <pre><tt>$ git commit ...
563 $ git reset --hard HEAD~
3 <b>(
1)
</b></tt></pre>
565 <div class=
"colist"><ol>
568 The last three commits (HEAD, HEAD^, and HEAD~
2) were bad
569 and you do not want to ever see them again. Do
<strong>not
</strong> do this if
570 you have already given these commits to somebody else. (See the
571 "RECOVERING FROM UPSTREAM REBASE" section in
<a href=
"git-rebase.html">git-rebase(
1)
</a> for
572 the implications of doing so.)
581 <div class=
"listingblock">
582 <div class=
"content">
583 <pre><tt>$ git pull
<b>(
1)
</b>
585 CONFLICT (content): Merge conflict in nitfol
586 Automatic merge failed; fix conflicts and then commit the result.
587 $ git reset --hard
<b>(
2)
</b>
588 $ git pull . topic/branch
<b>(
3)
</b>
589 Updating from
41223... to
13134...
591 $ git reset --hard ORIG_HEAD
<b>(
4)
</b></tt></pre>
593 <div class=
"colist"><ol>
596 Try to update from the upstream resulted in a lot of
597 conflicts; you were not ready to spend a lot of time merging
598 right now, so you decide to do that later.
603 "pull" has not made merge commit, so
"git reset --hard"
604 which is a synonym for
"git reset --hard HEAD" clears the mess
605 from the index file and the working tree.
610 Merge a topic branch into the current branch, which resulted
616 But you decided that the topic branch is not ready for public
617 consumption yet.
"pull" or
"merge" always leaves the original
618 tip of the current branch in ORIG_HEAD, so resetting hard to it
619 brings your index file and the working tree back to that state,
620 and resets the tip of the branch to that commit.
626 Undo a merge or pull inside a dirty work tree
629 <div class=
"listingblock">
630 <div class=
"content">
631 <pre><tt>$ git pull
<b>(
1)
</b>
633 Merge made by recursive.
634 nitfol |
20 +++++----
636 $ git reset --merge ORIG_HEAD
<b>(
2)
</b></tt></pre>
638 <div class=
"colist"><ol>
641 Even if you may have local modifications in your
642 working tree, you can safely say
"git pull" when you know
643 that the change in the other branch does not overlap with
649 After inspecting the result of the merge, you may find
650 that the change in the other branch is unsatisfactory. Running
651 "git reset --hard ORIG_HEAD" will let you go back to where you
652 were, but it will discard your local changes, which you do not
653 want.
"git reset --merge" keeps your local changes.
662 <div class=
"para"><p>Suppose you are interrupted by an urgent fix request while you
663 are in the middle of a large change. The files in your
664 working tree are not in any shape to be committed yet, but you
665 need to get to the other branch for a quick bugfix.
</p></div>
666 <div class=
"listingblock">
667 <div class=
"content">
668 <pre><tt>$ git checkout feature ;# you were working in
"feature" branch and
669 $ work work work ;# got interrupted
670 $ git commit -a -m
"snapshot WIP" <b>(
1)
</b>
671 $ git checkout master
673 $ git commit ;# commit with real log
674 $ git checkout feature
675 $ git reset --soft HEAD^ ;# go back to WIP state
<b>(
2)
</b>
676 $ git reset
<b>(
3)
</b></tt></pre>
678 <div class=
"colist"><ol>
681 This commit will get blown away so a throw-away log message is OK.
686 This removes the
<em>WIP
</em> commit from the commit history, and sets
687 your working tree to the state just before you made that snapshot.
692 At this point the index file still has all the WIP changes you
693 committed as
<em>snapshot WIP
</em>. This updates the index to show your
694 WIP files as uncommitted.
696 <div class=
"para"><p>See also
<a href=
"git-stash.html">git-stash(
1)
</a>.
</p></div>
701 Reset a single file in the index
704 <div class=
"para"><p>Suppose you have added a file to your index, but later decide you do not
705 want to add it to your commit. You can remove the file from the index
706 while keeping your changes with git reset.
</p></div>
707 <div class=
"listingblock">
708 <div class=
"content">
709 <pre><tt>$ git reset -- frotz.c
<b>(
1)
</b>
710 $ git commit -m
"Commit files in index" <b>(
2)
</b>
711 $ git add frotz.c
<b>(
3)
</b></tt></pre>
713 <div class=
"colist"><ol>
716 This removes the file from the index while keeping it in the working
722 This commits all other changes in the index.
727 Adds the file to the index again.
733 Keep changes in working tree while discarding some previous commits
736 <div class=
"para"><p>Suppose you are working on something and you commit it, and then you
737 continue working a bit more, but now you think that what you have in
738 your working tree should be in another branch that has nothing to do
739 with what you committed previously. You can start a new branch and
740 reset it while keeping the changes in your work tree.
</p></div>
741 <div class=
"listingblock">
742 <div class=
"content">
743 <pre><tt>$ git tag start
744 $ git checkout -b branch1
746 $ git commit ...
<b>(
1)
</b>
748 $ git checkout -b branch2
<b>(
2)
</b>
749 $ git reset --keep start
<b>(
3)
</b></tt></pre>
751 <div class=
"colist"><ol>
754 This commits your first edits in branch1.
759 In the ideal world, you could have realized that the earlier
760 commit did not belong to the new topic when you created and switched
761 to branch2 (i.e.
"git checkout -b branch2 start"), but nobody is
767 But you can use
"reset --keep" to remove the unwanted commit after
768 you switched to
"branch2".
775 <h2 id=
"_discussion">DISCUSSION
</h2>
776 <div class=
"sectionbody">
777 <div class=
"para"><p>The tables below show what happens when running:
</p></div>
778 <div class=
"listingblock">
779 <div class=
"content">
780 <pre><tt>git reset --option target
</tt></pre>
782 <div class=
"para"><p>to reset the HEAD to another commit (
<tt>target
</tt>) with the different
783 reset options depending on the state of the files.
</p></div>
784 <div class=
"para"><p>In these tables, A, B, C and D are some different states of a
785 file. For example, the first line of the first table means that if a
786 file is in state A in the working tree, in state B in the index, in
787 state C in HEAD and in state D in the target, then
"git reset --soft
788 target" will put the file in state A in the working tree, in state B
789 in the index and in state D in HEAD.
</p></div>
790 <div class=
"literalblock">
791 <div class=
"content">
792 <pre><tt>working index HEAD target working index HEAD
793 ----------------------------------------------------
798 --keep (disallowed)
</tt></pre>
800 <div class=
"literalblock">
801 <div class=
"content">
802 <pre><tt>working index HEAD target working index HEAD
803 ----------------------------------------------------
808 --keep A C C
</tt></pre>
810 <div class=
"literalblock">
811 <div class=
"content">
812 <pre><tt>working index HEAD target working index HEAD
813 ----------------------------------------------------
818 --keep (disallowed)
</tt></pre>
820 <div class=
"literalblock">
821 <div class=
"content">
822 <pre><tt>working index HEAD target working index HEAD
823 ----------------------------------------------------
828 --keep B C C
</tt></pre>
830 <div class=
"literalblock">
831 <div class=
"content">
832 <pre><tt>working index HEAD target working index HEAD
833 ----------------------------------------------------
838 --keep (disallowed)
</tt></pre>
840 <div class=
"literalblock">
841 <div class=
"content">
842 <pre><tt>working index HEAD target working index HEAD
843 ----------------------------------------------------
848 --keep B C C
</tt></pre>
850 <div class=
"para"><p>"reset --merge" is meant to be used when resetting out of a conflicted
851 merge. Any mergy operation guarantees that the work tree file that is
852 involved in the merge does not have local change wrt the index before
853 it starts, and that it writes the result out to the work tree. So if
854 we see some difference between the index and the target and also
855 between the index and the work tree, then it means that we are not
856 resetting out from a state that a mergy operation left after failing
857 with a conflict. That is why we disallow --merge option in this case.
</p></div>
858 <div class=
"para"><p>"reset --keep" is meant to be used when removing some of the last
859 commits in the current branch while keeping changes in the working
860 tree. If there could be conflicts between the changes in the commit we
861 want to remove and the changes in the working tree we want to keep,
862 the reset is disallowed. That's why it is disallowed if there are both
863 changes between the working tree and HEAD, and between HEAD and the
864 target. To be safe, it is also disallowed when there are unmerged
866 <div class=
"para"><p>The following tables show what happens when there are unmerged
868 <div class=
"literalblock">
869 <div class=
"content">
870 <pre><tt>working index HEAD target working index HEAD
871 ----------------------------------------------------
872 X U A B --soft (disallowed)
876 --keep (disallowed)
</tt></pre>
878 <div class=
"literalblock">
879 <div class=
"content">
880 <pre><tt>working index HEAD target working index HEAD
881 ----------------------------------------------------
882 X U A A --soft (disallowed)
886 --keep (disallowed)
</tt></pre>
888 <div class=
"para"><p>X means any state and U means an unmerged index.
</p></div>
890 <h2 id=
"_author">Author
</h2>
891 <div class=
"sectionbody">
892 <div class=
"para"><p>Written by Junio C Hamano
<gitster@pobox.com
> and Linus Torvalds
<torvalds@osdl.org
></p></div>
894 <h2 id=
"_documentation">Documentation
</h2>
895 <div class=
"sectionbody">
896 <div class=
"para"><p>Documentation by Junio C Hamano and the git-list
<git@vger.kernel.org
>.
</p></div>
898 <h2 id=
"_git">GIT
</h2>
899 <div class=
"sectionbody">
900 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
903 <div id=
"footer-text">
904 Last updated
2010-
09-
03 21:
30:
29 UTC