1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
6 <meta http-equiv=
"Content-Type" content=
"application/xhtml+xml; charset=UTF-8" />
7 <meta name=
"generator" content=
"AsciiDoc 10.2.0" />
8 <title>git-reset(
1)
</title>
9 <style type=
"text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
14 font-family: Georgia,serif;
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
22 #author, #revnumber, #revdate, #revremark,
24 font-family: Arial,Helvetica,sans-serif;
28 margin:
1em
5%
1em
5%;
33 text-decoration: underline;
49 h1, h2, h3, h4, h5, h6 {
57 border-bottom:
2px solid silver;
77 border:
1px solid silver;
88 ul
> li { color: #aaa; }
89 ul
> li
> * { color: black; }
91 .monospaced, code, pre {
92 font-family:
"Courier New", Courier, monospace;
99 white-space: pre-wrap;
109 #revnumber, #revdate, #revremark {
114 border-top:
2px solid silver;
120 padding-bottom:
0.5em;
124 padding-bottom:
0.5em;
129 margin-bottom:
1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
135 margin-bottom:
1.5em;
137 div.admonitionblock {
139 margin-bottom:
2.0em;
144 div.content { /* Block element content. */
148 /* Block element titles. */
149 div.title, caption.title {
154 margin-bottom:
0.5em;
160 td div.title:first-child {
163 div.content div.title:first-child {
166 div.content + div.title {
170 div.sidebarblock
> div.content {
172 border:
1px solid #dddddd;
173 border-left:
4px solid #f0f0f0;
177 div.listingblock
> div.content {
178 border:
1px solid #dddddd;
179 border-left:
5px solid #f0f0f0;
184 div.quoteblock, div.verseblock {
188 border-left:
5px solid #f0f0f0;
192 div.quoteblock
> div.attribution {
197 div.verseblock
> pre.content {
198 font-family: inherit;
201 div.verseblock
> div.attribution {
205 /* DEPRECATED: Pre version
8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
210 div.admonitionblock .icon {
214 text-decoration: underline;
216 padding-right:
0.5em;
218 div.admonitionblock td.content {
220 border-left:
3px solid #dddddd;
223 div.exampleblock
> div.content {
224 border-left:
3px solid #dddddd;
228 div.imageblock div.content { padding-left:
0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
234 margin-bottom:
0.8em;
247 list-style-position: outside;
250 list-style-type: decimal;
253 list-style-type: lower-alpha;
256 list-style-type: upper-alpha;
259 list-style-type: lower-roman;
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
269 margin-bottom:
0.1em;
281 margin-bottom:
0.8em;
284 padding-bottom:
15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
292 padding-right:
0.8em;
298 div.hdlist.compact tr {
307 .footnote, .footnoteref {
311 span.footnote, span.footnoteref {
312 vertical-align: super;
316 margin:
20px
0 20px
0;
320 #footnotes div.footnote {
326 border-top:
1px solid silver;
335 padding-right:
0.5em;
336 padding-bottom:
0.3em;
344 #footer-badges { display: none; }
348 margin-bottom:
2.5em;
356 margin-bottom:
0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size:
2em; }
411 span.small { font-size:
0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
427 margin-bottom:
1.5em;
429 div.tableblock
> table {
430 border:
3px solid #
527bbd;
432 thead, p.table.header {
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock
> table[
frame=
"void"] {
443 div.tableblock
> table[
frame=
"hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock
> table[
frame=
"vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
460 margin-bottom:
1.5em;
462 thead, p.tableblock.header {
473 border-color: #
527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
480 border-color: #
527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
498 th.tableblock.halign-center, td.tableblock.halign-center {
501 th.tableblock.halign-right, td.tableblock.halign-right {
505 th.tableblock.valign-top, td.tableblock.valign-top {
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
523 padding-bottom:
0.5em;
524 border-top:
2px solid silver;
525 border-bottom:
2px solid silver;
530 body.manpage div.sectionbody {
535 body.manpage div#toc { display: none; }
540 <script type=
"text/javascript">
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September
2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September
2006. License: GPL */
559 /* modified by Stuart Rackham,
2006,
2009. License: GPL */
562 toc: function (toclevels) {
564 function getText(el) {
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType ==
3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 else if (i.firstChild != null)
575 function TocEntry(el, text, toclevel) {
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([
1-'+(toclevels+
1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType ==
1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute(
"class") || i.getAttribute(
"className")) !=
"float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[
1]-
1);
602 var toc = document.getElementById(
"toc");
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
610 for (i =
0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute(
"class")
614 && entry.getAttribute(
"class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i =
0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById(
"content"), toclevels);
623 for (var i =
0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id ==
"")
626 entry.element.id =
"_toc_" + i;
627 var a = document.createElement(
"a");
628 a.href =
"#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement(
"div");
632 div.className =
"toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length ==
0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/
2005/
07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
651 var noteholder = document.getElementById(
"footnotes");
655 var entriesToRemove = [];
656 for (i =
0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute(
"class") ==
"footnote")
659 entriesToRemove.push(entry);
661 for (i =
0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById(
"content");
667 var spans = cont.getElementsByTagName(
"span");
670 for (i=
0; i
<spans.length; i++) {
671 if (spans[i].className ==
"footnote") {
673 var note = spans[i].getAttribute(
"data-note");
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[
1];
679 "[<a id='_footnoteref_" + n +
"' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n +
"</a>]";
681 spans[i].setAttribute(
"data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n +
"'>" +
685 "<a href='#_footnoteref_" + n +
"' title='Return to text'>" +
686 n +
"</a>. " + note +
"</div>";
687 var id =spans[i].getAttribute(
"id");
688 if (id != null) refs[
"#"+id] = n;
692 noteholder.parentNode.removeChild(noteholder);
694 // Process footnoterefs.
695 for (i=
0; i
<spans.length; i++) {
696 if (spans[i].className ==
"footnoteref") {
697 var href = spans[i].getElementsByTagName(
"a")[
0].getAttribute(
"href");
698 href = href.match(/#.*/)[
0]; // Because IE return full URL.
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n +
"</a>]";
708 install: function(toclevels) {
711 function reinstall() {
712 asciidoc.footnotes();
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
723 timerId = setInterval(reinstall,
500);
724 if (document.addEventListener)
725 document.addEventListener(
"DOMContentLoaded", reinstallAndRemoveTimer, false);
727 window.onload = reinstallAndRemoveTimer;
735 <body class=
"manpage">
738 git-reset(
1) Manual Page
741 <div class=
"sectionbody">
743 Reset current HEAD to the specified state
749 <h2 id=
"_synopsis">SYNOPSIS
</h2>
750 <div class=
"sectionbody">
751 <div class=
"verseblock">
752 <pre class=
"content"><em>git reset
</em> [-q] [
<tree-ish
>] [--]
<pathspec
>…
753 <em>git reset
</em> [-q] [--pathspec-from-file=
<file
> [--pathspec-file-nul]] [
<tree-ish
>]
754 <em>git reset
</em> (--patch | -p) [
<tree-ish
>] [--] [
<pathspec
>…]
755 <em>git reset
</em> [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [
<commit
>]
</pre>
756 <div class=
"attribution">
761 <h2 id=
"_description">DESCRIPTION
</h2>
762 <div class=
"sectionbody">
763 <div class=
"paragraph"><p>In the first three forms, copy entries from
<code><tree-ish
></code> to the index.
764 In the last form, set the current branch head (
<code>HEAD
</code>) to
<code><commit
></code>,
765 optionally modifying index and working tree to match.
766 The
<code><tree-ish
></code>/
<code><commit
></code> defaults to
<code>HEAD
</code> in all forms.
</p></div>
767 <div class=
"dlist"><dl>
769 <em>git reset
</em> [-q] [
<tree-ish
>] [--]
<pathspec
>…
772 <em>git reset
</em> [-q] [--pathspec-from-file=
<file
> [--pathspec-file-nul]] [
<tree-ish
>]
776 These forms reset the index entries for all paths that match the
777 <code><pathspec
></code> to their state at
<code><tree-ish
></code>. (It does not affect
778 the working tree or the current branch.)
780 <div class=
"paragraph"><p>This means that
<code>git reset
<pathspec
></code> is the opposite of
<code>git add
781 <pathspec
></code>. This command is equivalent to
782 <code>git restore [--source=
<tree-ish
>] --staged
<pathspec
>...
</code>.
</p></div>
783 <div class=
"paragraph"><p>After running
<code>git reset
<pathspec
></code> to update the index entry, you can
784 use
<a href=
"git-restore.html">git-restore(
1)
</a> to check the contents out of the index to
785 the working tree. Alternatively, using
<a href=
"git-restore.html">git-restore(
1)
</a>
786 and specifying a commit with
<code>--source
</code>, you
787 can copy the contents of a path out of a commit to the index and to the
788 working tree in one go.
</p></div>
791 <em>git reset
</em> (--patch | -p) [
<tree-ish
>] [--] [
<pathspec
>…]
795 Interactively select hunks in the difference between the index
796 and
<code><tree-ish
></code> (defaults to
<code>HEAD
</code>). The chosen hunks are applied
797 in reverse to the index.
799 <div class=
"paragraph"><p>This means that
<code>git reset -p
</code> is the opposite of
<code>git add -p
</code>, i.e.
800 you can use it to selectively reset hunks. See the
“Interactive Mode
”
801 section of
<a href=
"git-add.html">git-add(
1)
</a> to learn how to operate the
<code>--patch
</code> mode.
</p></div>
804 <em>git reset
</em> [
<mode
>] [
<commit
>]
808 This form resets the current branch head to
<code><commit
></code> and
809 possibly updates the index (resetting it to the tree of
<code><commit
></code>) and
810 the working tree depending on
<code><mode
></code>. Before the operation,
<code>ORIG_HEAD
</code>
811 is set to the tip of the current branch. If
<code><mode
></code> is omitted,
812 defaults to
<code>--mixed
</code>. The
<code><mode
></code> must be one of the following:
814 <div class=
"openblock">
815 <div class=
"content">
816 <div class=
"dlist"><dl>
822 Does not touch the index file or the working tree at all (but
823 resets the head to
<code><commit
></code>, just like all modes do). This leaves
824 all your changed files
"Changes to be committed", as
<code>git status
</code>
833 Resets the index but not the working tree (i.e., the changed files
834 are preserved but not marked for commit) and reports what has not
835 been updated. This is the default action.
837 <div class=
"paragraph"><p>If
<code>-N
</code> is specified, removed paths are marked as intent-to-add (see
838 <a href=
"git-add.html">git-add(
1)
</a>).
</p></div>
845 Resets the index and working tree. Any changes to tracked files in the
846 working tree since
<code><commit
></code> are discarded. Any untracked files or
847 directories in the way of writing any tracked files are simply deleted.
855 Resets the index and updates the files in the working tree that are
856 different between
<code><commit
></code> and
<code>HEAD
</code>, but keeps those which are
857 different between the index and working tree (i.e. which have changes
858 which have not been added).
859 If a file that is different between
<code><commit
></code> and the index has
860 unstaged changes, reset is aborted.
862 <div class=
"paragraph"><p>In other words,
<code>--merge
</code> does something like a
<code>git read-tree -u -m
<commit
></code>,
863 but carries forward unmerged index entries.
</p></div>
870 Resets index entries and updates files in the working tree that are
871 different between
<code><commit
></code> and
<code>HEAD
</code>.
872 If a file that is different between
<code><commit
></code> and
<code>HEAD
</code> has local
873 changes, reset is aborted.
877 --[no-]recurse-submodules
881 When the working tree is updated, using --recurse-submodules will
882 also recursively reset the working tree of all active submodules
883 according to the commit recorded in the superproject, also setting
884 the submodules' HEAD to be detached at that commit.
891 <div class=
"paragraph"><p>See
"Reset, restore and revert" in
<a href=
"git.html">git(
1)
</a> for the differences
892 between the three commands.
</p></div>
896 <h2 id=
"_options">OPTIONS
</h2>
897 <div class=
"sectionbody">
898 <div class=
"dlist"><dl>
907 Be quiet, only report errors.
918 Refresh the index after a mixed reset. Enabled by default.
922 --pathspec-from-file=
<file
>
926 Pathspec is passed in
<code><file
></code> instead of commandline args. If
927 <code><file
></code> is exactly
<code>-
</code> then standard input is used. Pathspec
928 elements are separated by LF or CR/LF. Pathspec elements can be
929 quoted as explained for the configuration variable
<code>core.quotePath
</code>
930 (see
<a href=
"git-config.html">git-config(
1)
</a>). See also
<code>--pathspec-file-nul
</code> and
931 global
<code>--literal-pathspecs
</code>.
939 Only meaningful with
<code>--pathspec-from-file
</code>. Pathspec elements are
940 separated with NUL character and all other characters are taken
941 literally (including newlines and quotes).
949 Do not interpret any more arguments as options.
953 <pathspec
>…
957 Limits the paths affected by the operation.
959 <div class=
"paragraph"><p>For more details, see the
<em>pathspec
</em> entry in
<a href=
"gitglossary.html">gitglossary(
7)
</a>.
</p></div>
965 <h2 id=
"_examples">EXAMPLES
</h2>
966 <div class=
"sectionbody">
967 <div class=
"dlist"><dl>
972 <div class=
"listingblock">
973 <div class=
"content">
974 <pre><code>$ edit
<b><1></b>
975 $ git add frotz.c filfre.c
976 $ mailx
<b><2></b>
977 $ git reset
<b><3></b>
978 $ git pull git://info.example.com/ nitfol
<b><4></b></code></pre>
980 <div class=
"colist arabic"><ol>
983 You are happily working on something, and find the changes
984 in these files are in good order. You do not want to see them
985 when you run
<code>git diff
</code>, because you plan to work on other files
986 and changes with these files are distracting.
991 Somebody asks you to pull, and the changes sound worthy of merging.
996 However, you already dirtied the index (i.e. your index does
997 not match the
<code>HEAD
</code> commit). But you know the pull you are going
998 to make does not affect
<code>frotz.c
</code> or
<code>filfre.c
</code>, so you revert the
999 index changes for these two files. Your changes in working tree
1005 Then you can pull and merge, leaving
<code>frotz.c
</code> and
<code>filfre.c
</code>
1006 changes still in the working tree.
1011 <dt class=
"hdlist1">
1012 Undo a commit and redo
1015 <div class=
"listingblock">
1016 <div class=
"content">
1017 <pre><code>$ git commit ...
1018 $ git reset --soft HEAD^
<b><1></b>
1019 $ edit
<b><2></b>
1020 $ git commit -a -c ORIG_HEAD
<b><3></b></code></pre>
1022 <div class=
"colist arabic"><ol>
1025 This is most often done when you remembered what you
1026 just committed is incomplete, or you misspelled your commit
1027 message, or both. Leaves working tree as it was before
"reset".
1032 Make corrections to working tree files.
1037 "reset" copies the old head to
<code>.git/ORIG_HEAD
</code>; redo the
1038 commit by starting with its log message. If you do not need to
1039 edit the message further, you can give
<code>-C
</code> option instead.
1041 <div class=
"paragraph"><p>See also the
<code>--amend
</code> option to
<a href=
"git-commit.html">git-commit(
1)
</a>.
</p></div>
1045 <dt class=
"hdlist1">
1046 Undo a commit, making it a topic branch
1049 <div class=
"listingblock">
1050 <div class=
"content">
1051 <pre><code>$ git branch topic/wip
<b><1></b>
1052 $ git reset --hard HEAD~
3 <b><2></b>
1053 $ git switch topic/wip
<b><3></b></code></pre>
1055 <div class=
"colist arabic"><ol>
1058 You have made some commits, but realize they were premature
1059 to be in the
<code>master
</code> branch. You want to continue polishing
1060 them in a topic branch, so create
<code>topic/wip
</code> branch off of the
1061 current
<code>HEAD
</code>.
1066 Rewind the master branch to get rid of those three commits.
1071 Switch to
<code>topic/wip
</code> branch and keep working.
1076 <dt class=
"hdlist1">
1077 Undo commits permanently
1080 <div class=
"listingblock">
1081 <div class=
"content">
1082 <pre><code>$ git commit ...
1083 $ git reset --hard HEAD~
3 <b><1></b></code></pre>
1085 <div class=
"colist arabic"><ol>
1088 The last three commits (
<code>HEAD
</code>,
<code>HEAD^
</code>, and
<code>HEAD~
2</code>) were bad
1089 and you do not want to ever see them again. Do
<strong>not
</strong> do this if
1090 you have already given these commits to somebody else. (See the
1091 "RECOVERING FROM UPSTREAM REBASE" section in
<a href=
"git-rebase.html">git-rebase(
1)
</a>
1092 for the implications of doing so.)
1097 <dt class=
"hdlist1">
1098 Undo a merge or pull
1101 <div class=
"listingblock">
1102 <div class=
"content">
1103 <pre><code>$ git pull
<b><1></b>
1105 CONFLICT (content): Merge conflict in nitfol
1106 Automatic merge failed; fix conflicts and then commit the result.
1107 $ git reset --hard
<b><2></b>
1108 $ git pull . topic/branch
<b><3></b>
1109 Updating from
41223... to
13134...
1111 $ git reset --hard ORIG_HEAD
<b><4></b></code></pre>
1113 <div class=
"colist arabic"><ol>
1116 Try to update from the upstream resulted in a lot of
1117 conflicts; you were not ready to spend a lot of time merging
1118 right now, so you decide to do that later.
1123 "pull" has not made merge commit, so
<code>git reset --hard
</code>
1124 which is a synonym for
<code>git reset --hard HEAD
</code> clears the mess
1125 from the index file and the working tree.
1130 Merge a topic branch into the current branch, which resulted
1136 But you decided that the topic branch is not ready for public
1137 consumption yet.
"pull" or
"merge" always leaves the original
1138 tip of the current branch in
<code>ORIG_HEAD
</code>, so resetting hard to it
1139 brings your index file and the working tree back to that state,
1140 and resets the tip of the branch to that commit.
1145 <dt class=
"hdlist1">
1146 Undo a merge or pull inside a dirty working tree
1149 <div class=
"listingblock">
1150 <div class=
"content">
1151 <pre><code>$ git pull
<b><1></b>
1153 Merge made by recursive.
1154 nitfol |
20 +++++----
1156 $ git reset --merge ORIG_HEAD
<b><2></b></code></pre>
1158 <div class=
"colist arabic"><ol>
1161 Even if you may have local modifications in your
1162 working tree, you can safely say
<code>git pull
</code> when you know
1163 that the change in the other branch does not overlap with
1169 After inspecting the result of the merge, you may find
1170 that the change in the other branch is unsatisfactory. Running
1171 <code>git reset --hard ORIG_HEAD
</code> will let you go back to where you
1172 were, but it will discard your local changes, which you do not
1173 want.
<code>git reset --merge
</code> keeps your local changes.
1178 <dt class=
"hdlist1">
1179 Interrupted workflow
1182 <div class=
"paragraph"><p>Suppose you are interrupted by an urgent fix request while you
1183 are in the middle of a large change. The files in your
1184 working tree are not in any shape to be committed yet, but you
1185 need to get to the other branch for a quick bugfix.
</p></div>
1186 <div class=
"listingblock">
1187 <div class=
"content">
1188 <pre><code>$ git switch feature ;# you were working in
"feature" branch and
1189 $ work work work ;# got interrupted
1190 $ git commit -a -m
"snapshot WIP" <b><1></b>
1193 $ git commit ;# commit with real log
1194 $ git switch feature
1195 $ git reset --soft HEAD^ ;# go back to WIP state
<b><2></b>
1196 $ git reset
<b><3></b></code></pre>
1198 <div class=
"colist arabic"><ol>
1201 This commit will get blown away so a throw-away log message is OK.
1206 This removes the
<em>WIP
</em> commit from the commit history, and sets
1207 your working tree to the state just before you made that snapshot.
1212 At this point the index file still has all the WIP changes you
1213 committed as
<em>snapshot WIP
</em>. This updates the index to show your
1214 WIP files as uncommitted.
1216 <div class=
"paragraph"><p>See also
<a href=
"git-stash.html">git-stash(
1)
</a>.
</p></div>
1220 <dt class=
"hdlist1">
1221 Reset a single file in the index
1224 <div class=
"paragraph"><p>Suppose you have added a file to your index, but later decide you do not
1225 want to add it to your commit. You can remove the file from the index
1226 while keeping your changes with git reset.
</p></div>
1227 <div class=
"listingblock">
1228 <div class=
"content">
1229 <pre><code>$ git reset -- frotz.c
<b><1></b>
1230 $ git commit -m
"Commit files in index" <b><2></b>
1231 $ git add frotz.c
<b><3></b></code></pre>
1233 <div class=
"colist arabic"><ol>
1236 This removes the file from the index while keeping it in the working
1242 This commits all other changes in the index.
1247 Adds the file to the index again.
1252 <dt class=
"hdlist1">
1253 Keep changes in working tree while discarding some previous commits
1256 <div class=
"paragraph"><p>Suppose you are working on something and you commit it, and then you
1257 continue working a bit more, but now you think that what you have in
1258 your working tree should be in another branch that has nothing to do
1259 with what you committed previously. You can start a new branch and
1260 reset it while keeping the changes in your working tree.
</p></div>
1261 <div class=
"listingblock">
1262 <div class=
"content">
1263 <pre><code>$ git tag start
1264 $ git switch -c branch1
1266 $ git commit ...
<b><1></b>
1268 $ git switch -c branch2
<b><2></b>
1269 $ git reset --keep start
<b><3></b></code></pre>
1271 <div class=
"colist arabic"><ol>
1274 This commits your first edits in
<code>branch1
</code>.
1279 In the ideal world, you could have realized that the earlier
1280 commit did not belong to the new topic when you created and switched
1281 to
<code>branch2
</code> (i.e.
<code>git switch -c branch2 start
</code>), but nobody is
1287 But you can use
<code>reset --keep
</code> to remove the unwanted commit after
1288 you switched to
<code>branch2
</code>.
1293 <dt class=
"hdlist1">
1294 Split a commit apart into a sequence of commits
1297 <div class=
"paragraph"><p>Suppose that you have created lots of logically separate changes and committed
1298 them together. Then, later you decide that it might be better to have each
1299 logical chunk associated with its own commit. You can use git reset to rewind
1300 history without changing the contents of your local files, and then successively
1301 use
<code>git add -p
</code> to interactively select which hunks to include into each commit,
1302 using
<code>git commit -c
</code> to pre-populate the commit message.
</p></div>
1303 <div class=
"listingblock">
1304 <div class=
"content">
1305 <pre><code>$ git reset -N HEAD^
<b><1></b>
1306 $ git add -p
<b><2></b>
1307 $ git diff --cached
<b><3></b>
1308 $ git commit -c HEAD@{
1}
<b><4></b>
1309 ...
<b><5></b>
1310 $ git add ...
<b><6></b>
1311 $ git diff --cached
<b><7></b>
1312 $ git commit ...
<b><8></b></code></pre>
1314 <div class=
"colist arabic"><ol>
1317 First, reset the history back one commit so that we remove the original
1318 commit, but leave the working tree with all the changes. The -N ensures
1319 that any new files added with
<code>HEAD
</code> are still marked so that
<code>git add -p
</code>
1325 Next, we interactively select diff hunks to add using the
<code>git add -p
</code>
1326 facility. This will ask you about each diff hunk in sequence and you can
1327 use simple commands such as
"yes, include this",
"No don’t include this"
1328 or even the very powerful
"edit" facility.
1333 Once satisfied with the hunks you want to include, you should verify what
1334 has been prepared for the first commit by using
<code>git diff --cached
</code>. This
1335 shows all the changes that have been moved into the index and are about
1341 Next, commit the changes stored in the index. The
<code>-c
</code> option specifies to
1342 pre-populate the commit message from the original message that you started
1343 with in the first commit. This is helpful to avoid retyping it. The
1344 <code>HEAD@{
1}
</code> is a special notation for the commit that
<code>HEAD
</code> used to be at
1345 prior to the original reset commit (
1 change ago).
1346 See
<a href=
"git-reflog.html">git-reflog(
1)
</a> for more details. You may also use any other
1347 valid commit reference.
1352 You can repeat steps
2-
4 multiple times to break the original code into
1353 any number of commits.
1358 Now you
’ve split out many of the changes into their own commits, and might
1359 no longer use the patch mode of
<code>git add
</code>, in order to select all remaining
1360 uncommitted changes.
1365 Once again, check to verify that you
’ve included what you want to. You may
1366 also wish to verify that git diff doesn
’t show any remaining changes to be
1372 And finally create the final commit.
1381 <h2 id=
"_discussion">DISCUSSION
</h2>
1382 <div class=
"sectionbody">
1383 <div class=
"paragraph"><p>The tables below show what happens when running:
</p></div>
1384 <div class=
"listingblock">
1385 <div class=
"content">
1386 <pre><code>git reset --option target
</code></pre>
1388 <div class=
"paragraph"><p>to reset the
<code>HEAD
</code> to another commit (
<code>target
</code>) with the different
1389 reset options depending on the state of the files.
</p></div>
1390 <div class=
"paragraph"><p>In these tables,
<code>A
</code>,
<code>B
</code>,
<code>C
</code> and
<code>D
</code> are some different states of a
1391 file. For example, the first line of the first table means that if a
1392 file is in state
<code>A
</code> in the working tree, in state
<code>B
</code> in the index, in
1393 state
<code>C
</code> in
<code>HEAD
</code> and in state
<code>D
</code> in the target, then
<code>git reset --soft
1394 target
</code> will leave the file in the working tree in state
<code>A
</code> and in the
1395 index in state
<code>B
</code>. It resets (i.e. moves) the
<code>HEAD
</code> (i.e. the tip of
1396 the current branch, if you are on one) to
<code>target
</code> (which has the file
1397 in state
<code>D
</code>).
</p></div>
1398 <div class=
"literalblock">
1399 <div class=
"content">
1400 <pre><code>working index HEAD target working index HEAD
1401 ----------------------------------------------------
1402 A B C D --soft A B D
1405 --merge (disallowed)
1406 --keep (disallowed)
</code></pre>
1408 <div class=
"literalblock">
1409 <div class=
"content">
1410 <pre><code>working index HEAD target working index HEAD
1411 ----------------------------------------------------
1412 A B C C --soft A B C
1415 --merge (disallowed)
1416 --keep A C C
</code></pre>
1418 <div class=
"literalblock">
1419 <div class=
"content">
1420 <pre><code>working index HEAD target working index HEAD
1421 ----------------------------------------------------
1422 B B C D --soft B B D
1426 --keep (disallowed)
</code></pre>
1428 <div class=
"literalblock">
1429 <div class=
"content">
1430 <pre><code>working index HEAD target working index HEAD
1431 ----------------------------------------------------
1432 B B C C --soft B B C
1436 --keep B C C
</code></pre>
1438 <div class=
"literalblock">
1439 <div class=
"content">
1440 <pre><code>working index HEAD target working index HEAD
1441 ----------------------------------------------------
1442 B C C D --soft B C D
1445 --merge (disallowed)
1446 --keep (disallowed)
</code></pre>
1448 <div class=
"literalblock">
1449 <div class=
"content">
1450 <pre><code>working index HEAD target working index HEAD
1451 ----------------------------------------------------
1452 B C C C --soft B C C
1456 --keep B C C
</code></pre>
1458 <div class=
"paragraph"><p><code>reset --merge
</code> is meant to be used when resetting out of a conflicted
1459 merge. Any mergy operation guarantees that the working tree file that is
1460 involved in the merge does not have a local change with respect to the index
1461 before it starts, and that it writes the result out to the working tree. So if
1462 we see some difference between the index and the target and also
1463 between the index and the working tree, then it means that we are not
1464 resetting out from a state that a mergy operation left after failing
1465 with a conflict. That is why we disallow
<code>--merge
</code> option in this case.
</p></div>
1466 <div class=
"paragraph"><p><code>reset --keep
</code> is meant to be used when removing some of the last
1467 commits in the current branch while keeping changes in the working
1468 tree. If there could be conflicts between the changes in the commit we
1469 want to remove and the changes in the working tree we want to keep,
1470 the reset is disallowed. That
’s why it is disallowed if there are both
1471 changes between the working tree and
<code>HEAD
</code>, and between
<code>HEAD
</code> and the
1472 target. To be safe, it is also disallowed when there are unmerged
1474 <div class=
"paragraph"><p>The following tables show what happens when there are unmerged
1476 <div class=
"literalblock">
1477 <div class=
"content">
1478 <pre><code>working index HEAD target working index HEAD
1479 ----------------------------------------------------
1480 X U A B --soft (disallowed)
1484 --keep (disallowed)
</code></pre>
1486 <div class=
"literalblock">
1487 <div class=
"content">
1488 <pre><code>working index HEAD target working index HEAD
1489 ----------------------------------------------------
1490 X U A A --soft (disallowed)
1494 --keep (disallowed)
</code></pre>
1496 <div class=
"paragraph"><p><code>X
</code> means any state and
<code>U
</code> means an unmerged index.
</p></div>
1500 <h2 id=
"_git">GIT
</h2>
1501 <div class=
"sectionbody">
1502 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1506 <div id=
"footnotes"><hr /></div>
1508 <div id=
"footer-text">
1510 2023-
01-
21 17:
52:
14 PST