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> [--mixed | --soft | --hard | --merge] [-q] [
<commit
>]
325 <em>git reset
</em> [-q] [
<commit
>] [--]
<paths
>…
326 <em>git reset
</em> --patch [
<commit
>] [--] [
<paths
>…]
</div></div>
328 <h2 id=
"_description">DESCRIPTION
</h2>
329 <div class=
"sectionbody">
330 <div class=
"para"><p>Sets the current head to the specified commit and optionally resets the
331 index and working tree to match.
</p></div>
332 <div class=
"para"><p>This command is useful if you notice some small error in a recent
333 commit (or set of commits) and want to redo that part without showing
334 the undo in the history.
</p></div>
335 <div class=
"para"><p>If you want to undo a commit other than the latest on a branch,
336 <a href=
"git-revert.html">git-revert(
1)
</a> is your friend.
</p></div>
337 <div class=
"para"><p>The second and third forms with
<em>paths
</em> and/or --patch are used to
338 revert selected paths in the index from a given commit, without moving
341 <h2 id=
"_options">OPTIONS
</h2>
342 <div class=
"sectionbody">
343 <div class=
"vlist"><dl>
349 Resets the index but not the working tree (i.e., the changed files
350 are preserved but not marked for commit) and reports what has not
351 been updated. This is the default action.
359 Does not touch the index file nor the working tree at all, but
360 requires them to be in a good order. This leaves all your changed
361 files
"Changes to be committed", as
<em>git-status
</em> would
370 Matches the working tree and index to that of the tree being
371 switched to. Any changes to tracked files in the working tree
372 since
<commit
> are lost.
380 Resets the index to match the tree recorded by the named commit,
381 and updates the files that are different between the named commit
382 and the current commit in the working tree.
393 Interactively select hunks in the difference between the index
394 and
<commit
> (defaults to HEAD). The chosen hunks are applied
395 in reverse to the index.
397 <div class=
"para"><p>This means that
<tt>git reset -p
</tt> is the opposite of
<tt>git add -p
</tt> (see
398 <a href=
"git-add.html">git-add(
1)
</a>).
</p></div>
408 Be quiet, only report errors.
416 Commit to make the current HEAD. If not given defaults to HEAD.
421 <h2 id=
"_examples">Examples
</h2>
422 <div class=
"sectionbody">
423 <div class=
"vlist"><dl>
425 Undo a commit and redo
428 <div class=
"listingblock">
429 <div class=
"content">
430 <pre><tt>$ git commit ...
431 $ git reset --soft HEAD^
<b>(
1)
</b>
433 $ git commit -a -c ORIG_HEAD
<b>(
3)
</b></tt></pre>
435 <div class=
"colist"><ol>
438 This is most often done when you remembered what you
439 just committed is incomplete, or you misspelled your commit
440 message, or both. Leaves working tree as it was before
"reset".
445 Make corrections to working tree files.
450 "reset" copies the old head to .git/ORIG_HEAD; redo the
451 commit by starting with its log message. If you do not need to
452 edit the message further, you can give -C option instead.
454 <div class=
"para"><p>See also the --amend option to
<a href=
"git-commit.html">git-commit(
1)
</a>.
</p></div>
459 Undo commits permanently
462 <div class=
"listingblock">
463 <div class=
"content">
464 <pre><tt>$ git commit ...
465 $ git reset --hard HEAD~
3 <b>(
1)
</b></tt></pre>
467 <div class=
"colist"><ol>
470 The last three commits (HEAD, HEAD^, and HEAD~
2) were bad
471 and you do not want to ever see them again. Do
<strong>not
</strong> do this if
472 you have already given these commits to somebody else. (See the
473 "RECOVERING FROM UPSTREAM REBASE" section in
<a href=
"git-rebase.html">git-rebase(
1)
</a> for
474 the implications of doing so.)
480 Undo a commit, making it a topic branch
483 <div class=
"listingblock">
484 <div class=
"content">
485 <pre><tt>$ git branch topic/wip
<b>(
1)
</b>
486 $ git reset --hard HEAD~
3 <b>(
2)
</b>
487 $ git checkout topic/wip
<b>(
3)
</b></tt></pre>
489 <div class=
"colist"><ol>
492 You have made some commits, but realize they were premature
493 to be in the
"master" branch. You want to continue polishing
494 them in a topic branch, so create
"topic/wip" branch off of the
500 Rewind the master branch to get rid of those three commits.
505 Switch to
"topic/wip" branch and keep working.
514 <div class=
"listingblock">
515 <div class=
"content">
516 <pre><tt>$ edit
<b>(
1)
</b>
517 $ git add frotz.c filfre.c
519 $ git reset
<b>(
3)
</b>
520 $ git pull git://info.example.com/ nitfol
<b>(
4)
</b></tt></pre>
522 <div class=
"colist"><ol>
525 You are happily working on something, and find the changes
526 in these files are in good order. You do not want to see them
527 when you run
"git diff", because you plan to work on other files
528 and changes with these files are distracting.
533 Somebody asks you to pull, and the changes sounds worthy of merging.
538 However, you already dirtied the index (i.e. your index does
539 not match the HEAD commit). But you know the pull you are going
540 to make does not affect frotz.c nor filfre.c, so you revert the
541 index changes for these two files. Your changes in working tree
547 Then you can pull and merge, leaving frotz.c and filfre.c
548 changes still in the working tree.
557 <div class=
"listingblock">
558 <div class=
"content">
559 <pre><tt>$ git pull
<b>(
1)
</b>
561 CONFLICT (content): Merge conflict in nitfol
562 Automatic merge failed; fix conflicts and then commit the result.
563 $ git reset --hard
<b>(
2)
</b>
564 $ git pull . topic/branch
<b>(
3)
</b>
565 Updating from
41223... to
13134...
567 $ git reset --hard ORIG_HEAD
<b>(
4)
</b></tt></pre>
569 <div class=
"colist"><ol>
572 Try to update from the upstream resulted in a lot of
573 conflicts; you were not ready to spend a lot of time merging
574 right now, so you decide to do that later.
579 "pull" has not made merge commit, so
"git reset --hard"
580 which is a synonym for
"git reset --hard HEAD" clears the mess
581 from the index file and the working tree.
586 Merge a topic branch into the current branch, which resulted
592 But you decided that the topic branch is not ready for public
593 consumption yet.
"pull" or
"merge" always leaves the original
594 tip of the current branch in ORIG_HEAD, so resetting hard to it
595 brings your index file and the working tree back to that state,
596 and resets the tip of the branch to that commit.
602 Undo a merge or pull inside a dirty work tree
605 <div class=
"listingblock">
606 <div class=
"content">
607 <pre><tt>$ git pull
<b>(
1)
</b>
609 Merge made by recursive.
610 nitfol |
20 +++++----
612 $ git reset --merge ORIG_HEAD
<b>(
2)
</b></tt></pre>
614 <div class=
"colist"><ol>
617 Even if you may have local modifications in your
618 working tree, you can safely say
"git pull" when you know
619 that the change in the other branch does not overlap with
625 After inspecting the result of the merge, you may find
626 that the change in the other branch is unsatisfactory. Running
627 "git reset --hard ORIG_HEAD" will let you go back to where you
628 were, but it will discard your local changes, which you do not
629 want.
"git reset --merge" keeps your local changes.
638 <div class=
"para"><p>Suppose you are interrupted by an urgent fix request while you
639 are in the middle of a large change. The files in your
640 working tree are not in any shape to be committed yet, but you
641 need to get to the other branch for a quick bugfix.
</p></div>
642 <div class=
"listingblock">
643 <div class=
"content">
644 <pre><tt>$ git checkout feature ;# you were working in
"feature" branch and
645 $ work work work ;# got interrupted
646 $ git commit -a -m
"snapshot WIP" <b>(
1)
</b>
647 $ git checkout master
649 $ git commit ;# commit with real log
650 $ git checkout feature
651 $ git reset --soft HEAD^ ;# go back to WIP state
<b>(
2)
</b>
652 $ git reset
<b>(
3)
</b></tt></pre>
654 <div class=
"colist"><ol>
657 This commit will get blown away so a throw-away log message is OK.
662 This removes the
<em>WIP
</em> commit from the commit history, and sets
663 your working tree to the state just before you made that snapshot.
668 At this point the index file still has all the WIP changes you
669 committed as
<em>snapshot WIP
</em>. This updates the index to show your
670 WIP files as uncommitted.
672 <div class=
"para"><p>See also
<a href=
"git-stash.html">git-stash(
1)
</a>.
</p></div>
677 Reset a single file in the index
680 <div class=
"para"><p>Suppose you have added a file to your index, but later decide you do not
681 want to add it to your commit. You can remove the file from the index
682 while keeping your changes with git reset.
</p></div>
683 <div class=
"listingblock">
684 <div class=
"content">
685 <pre><tt>$ git reset -- frotz.c
<b>(
1)
</b>
686 $ git commit -m
"Commit files in index" <b>(
2)
</b>
687 $ git add frotz.c
<b>(
3)
</b></tt></pre>
689 <div class=
"colist"><ol>
692 This removes the file from the index while keeping it in the working
698 This commits all other changes in the index.
703 Adds the file to the index again.
710 <h2 id=
"_author">Author
</h2>
711 <div class=
"sectionbody">
712 <div class=
"para"><p>Written by Junio C Hamano
<gitster@pobox.com
> and Linus Torvalds
<torvalds@osdl.org
></p></div>
714 <h2 id=
"_documentation">Documentation
</h2>
715 <div class=
"sectionbody">
716 <div class=
"para"><p>Documentation by Junio C Hamano and the git-list
<git@vger.kernel.org
>.
</p></div>
718 <h2 id=
"_git">GIT
</h2>
719 <div class=
"sectionbody">
720 <div class=
"para"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
723 <div id=
"footer-text">
724 Last updated
2010-
01-
10 19:
52:
59 UTC