summaryrefslogtreecommitdiffstats
path: root/man1/git-reset.1
diff options
context:
space:
mode:
Diffstat (limited to 'man1/git-reset.1')
-rw-r--r--man1/git-reset.1216
1 files changed, 145 insertions, 71 deletions
diff --git a/man1/git-reset.1 b/man1/git-reset.1
index 206fe6295..4eab32eb1 100644
--- a/man1/git-reset.1
+++ b/man1/git-reset.1
@@ -2,12 +2,12 @@
.\" Title: git-reset
.\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\" Date: 2023-05-09
+.\" Date: 2023-05-10
.\" Manual: Git Manual
-.\" Source: Git 2.40.1.515.g5597cfdf47
+.\" Source: Git 2.40.1.552.g91428f078b
.\" Language: English
.\"
-.TH "GIT\-RESET" "1" "2023\-05\-09" "Git 2\&.40\&.1\&.515\&.g5597cf" "Git Manual"
+.TH "GIT\-RESET" "1" "2023\-05\-10" "Git 2\&.40\&.1\&.552\&.g91428f" "Git Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -224,24 +224,32 @@ $ git pull git://info\&.example\&.com/ nitfol \fB(4)\fR
.RE
.\}
.sp
-\fB1. \fRYou are happily working on something, and find the changes in these files are in good order\&. You do not want to see them when you run
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+You are happily working on something, and find the changes in these files are in good order\&. You do not want to see them when you run
\fBgit diff\fR, because you plan to work on other files and changes with these files are distracting\&.
-.br
-\fB2. \fRSomebody asks you to pull, and the changes sound worthy of merging\&.
-.br
-\fB3. \fRHowever, you already dirtied the index (i\&.e\&. your index does not match the
+T}
+\fB2.\fR\h'-2n':T{
+Somebody asks you to pull, and the changes sound worthy of merging\&.
+T}
+\fB3.\fR\h'-2n':T{
+However, you already dirtied the index (i\&.e\&. your index does not match the
\fBHEAD\fR
commit)\&. But you know the pull you are going to make does not affect
\fBfrotz\&.c\fR
or
\fBfilfre\&.c\fR, so you revert the index changes for these two files\&. Your changes in working tree remain there\&.
-.br
-\fB4. \fRThen you can pull and merge, leaving
+T}
+\fB4.\fR\h'-2n':T{
+Then you can pull and merge, leaving
\fBfrotz\&.c\fR
and
\fBfilfre\&.c\fR
changes still in the working tree\&.
-.br
+T}
+.TE
.RE
.PP
Undo a commit and redo
@@ -260,11 +268,17 @@ $ git commit \-a \-c ORIG_HEAD \fB(3)\fR
.RE
.\}
.sp
-\fB1. \fRThis is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both\&. Leaves working tree as it was before "reset"\&.
-.br
-\fB2. \fRMake corrections to working tree files\&.
-.br
-\fB3. \fR"reset" copies the old head to
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both\&. Leaves working tree as it was before "reset"\&.
+T}
+\fB2.\fR\h'-2n':T{
+Make corrections to working tree files\&.
+T}
+\fB3.\fR\h'-2n':T{
+"reset" copies the old head to
\fB\&.git/ORIG_HEAD\fR; redo the commit by starting with its log message\&. If you do not need to edit the message further, you can give
\fB\-C\fR
option instead\&.
@@ -273,7 +287,8 @@ See also the
\fB\-\-amend\fR
option to
\fBgit-commit\fR(1)\&.
-.br
+T}
+.TE
.RE
.PP
Undo a commit, making it a topic branch
@@ -291,19 +306,26 @@ $ git switch topic/wip \fB(3)\fR
.RE
.\}
.sp
-\fB1. \fRYou have made some commits, but realize they were premature to be in the
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+You have made some commits, but realize they were premature to be in the
\fBmaster\fR
branch\&. You want to continue polishing them in a topic branch, so create
\fBtopic/wip\fR
branch off of the current
\fBHEAD\fR\&.
-.br
-\fB2. \fRRewind the master branch to get rid of those three commits\&.
-.br
-\fB3. \fRSwitch to
+T}
+\fB2.\fR\h'-2n':T{
+Rewind the master branch to get rid of those three commits\&.
+T}
+\fB3.\fR\h'-2n':T{
+Switch to
\fBtopic/wip\fR
branch and keep working\&.
-.br
+T}
+.TE
.RE
.PP
Undo commits permanently
@@ -320,14 +342,19 @@ $ git reset \-\-hard HEAD~3 \fB(1)\fR
.RE
.\}
.sp
-\fB1. \fRThe last three commits (\fBHEAD\fR,
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+The last three commits (\fBHEAD\fR,
\fBHEAD^\fR, and
\fBHEAD~2\fR) were bad and you do not want to ever see them again\&. Do
\fBnot\fR
do this if you have already given these commits to somebody else\&. (See the "RECOVERING FROM UPSTREAM REBASE" section in
\fBgit-rebase\fR(1)
for the implications of doing so\&.)
-.br
+T}
+.TE
.RE
.PP
Undo a merge or pull
@@ -351,19 +378,27 @@ $ git reset \-\-hard ORIG_HEAD \fB(4)\fR
.RE
.\}
.sp
-\fB1. \fRTry to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later\&.
-.br
-\fB2. \fR"pull" has not made merge commit, so
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+Try to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later\&.
+T}
+\fB2.\fR\h'-2n':T{
+"pull" has not made merge commit, so
\fBgit reset \-\-hard\fR
which is a synonym for
\fBgit reset \-\-hard HEAD\fR
clears the mess from the index file and the working tree\&.
-.br
-\fB3. \fRMerge a topic branch into the current branch, which resulted in a fast\-forward\&.
-.br
-\fB4. \fRBut you decided that the topic branch is not ready for public consumption yet\&. "pull" or "merge" always leaves the original tip of the current branch in
+T}
+\fB3.\fR\h'-2n':T{
+Merge a topic branch into the current branch, which resulted in a fast\-forward\&.
+T}
+\fB4.\fR\h'-2n':T{
+But you decided that the topic branch is not ready for public consumption yet\&. "pull" or "merge" always leaves the original tip of the current branch in
\fBORIG_HEAD\fR, so resetting hard to it brings your index file and the working tree back to that state, and resets the tip of the branch to that commit\&.
-.br
+T}
+.TE
.RE
.PP
Undo a merge or pull inside a dirty working tree
@@ -384,16 +419,22 @@ $ git reset \-\-merge ORIG_HEAD \fB(2)\fR
.RE
.\}
.sp
-\fB1. \fREven if you may have local modifications in your working tree, you can safely say
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+Even if you may have local modifications in your working tree, you can safely say
\fBgit pull\fR
when you know that the change in the other branch does not overlap with them\&.
-.br
-\fB2. \fRAfter inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory\&. Running
+T}
+\fB2.\fR\h'-2n':T{
+After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory\&. Running
\fBgit reset \-\-hard ORIG_HEAD\fR
will let you go back to where you were, but it will discard your local changes, which you do not want\&.
\fBgit reset \-\-merge\fR
keeps your local changes\&.
-.br
+T}
+.TE
.RE
.PP
Interrupted workflow
@@ -418,18 +459,25 @@ $ git reset \fB(3)\fR
.RE
.\}
.sp
-\fB1. \fRThis commit will get blown away so a throw\-away log message is OK\&.
-.br
-\fB2. \fRThis removes the
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+This commit will get blown away so a throw\-away log message is OK\&.
+T}
+\fB2.\fR\h'-2n':T{
+This removes the
\fIWIP\fR
commit from the commit history, and sets your working tree to the state just before you made that snapshot\&.
-.br
-\fB3. \fRAt this point the index file still has all the WIP changes you committed as
+T}
+\fB3.\fR\h'-2n':T{
+At this point the index file still has all the WIP changes you committed as
\fIsnapshot WIP\fR\&. This updates the index to show your WIP files as uncommitted\&.
.sp
See also
\fBgit-stash\fR(1)\&.
-.br
+T}
+.TE
.RE
.PP
Reset a single file in the index
@@ -448,12 +496,19 @@ $ git add frotz\&.c \fB(3)\fR
.RE
.\}
.sp
-\fB1. \fRThis removes the file from the index while keeping it in the working directory\&.
-.br
-\fB2. \fRThis commits all other changes in the index\&.
-.br
-\fB3. \fRAdds the file to the index again\&.
-.br
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+This removes the file from the index while keeping it in the working directory\&.
+T}
+\fB2.\fR\h'-2n':T{
+This commits all other changes in the index\&.
+T}
+\fB3.\fR\h'-2n':T{
+Adds the file to the index again\&.
+T}
+.TE
.RE
.PP
Keep changes in working tree while discarding some previous commits
@@ -476,19 +531,26 @@ $ git reset \-\-keep start \fB(3)\fR
.RE
.\}
.sp
-\fB1. \fRThis commits your first edits in
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+This commits your first edits in
\fBbranch1\fR\&.
-.br
-\fB2. \fRIn the ideal world, you could have realized that the earlier commit did not belong to the new topic when you created and switched to
+T}
+\fB2.\fR\h'-2n':T{
+In the ideal world, you could have realized that the earlier commit did not belong to the new topic when you created and switched to
\fBbranch2\fR
(i\&.e\&.
\fBgit switch \-c branch2 start\fR), but nobody is perfect\&.
-.br
-\fB3. \fRBut you can use
+T}
+\fB3.\fR\h'-2n':T{
+But you can use
\fBreset \-\-keep\fR
to remove the unwanted commit after you switched to
\fBbranch2\fR\&.
-.br
+T}
+.TE
.RE
.PP
Split a commit apart into a sequence of commits
@@ -516,20 +578,27 @@ $ git commit \&.\&.\&. \fB(8)\fR
.RE
.\}
.sp
-\fB1. \fRFirst, reset the history back one commit so that we remove the original commit, but leave the working tree with all the changes\&. The \-N ensures that any new files added with
+.TS
+tab(:);
+r lw(\n(.lu*75u/100u).
+\fB1.\fR\h'-2n':T{
+First, reset the history back one commit so that we remove the original commit, but leave the working tree with all the changes\&. The \-N ensures that any new files added with
\fBHEAD\fR
are still marked so that
\fBgit add \-p\fR
will find them\&.
-.br
-\fB2. \fRNext, we interactively select diff hunks to add using the
+T}
+\fB2.\fR\h'-2n':T{
+Next, we interactively select diff hunks to add using the
\fBgit add \-p\fR
facility\&. This will ask you about each diff hunk in sequence and you can use simple commands such as "yes, include this", "No don\(cqt include this" or even the very powerful "edit" facility\&.
-.br
-\fB3. \fROnce satisfied with the hunks you want to include, you should verify what has been prepared for the first commit by using
+T}
+\fB3.\fR\h'-2n':T{
+Once satisfied with the hunks you want to include, you should verify what has been prepared for the first commit by using
\fBgit diff \-\-cached\fR\&. This shows all the changes that have been moved into the index and are about to be committed\&.
-.br
-\fB4. \fRNext, commit the changes stored in the index\&. The
+T}
+\fB4.\fR\h'-2n':T{
+Next, commit the changes stored in the index\&. The
\fB\-c\fR
option specifies to pre\-populate the commit message from the original message that you started with in the first commit\&. This is helpful to avoid retyping it\&. The
\fBHEAD@{1}\fR
@@ -538,16 +607,21 @@ is a special notation for the commit that
used to be at prior to the original reset commit (1 change ago)\&. See
\fBgit-reflog\fR(1)
for more details\&. You may also use any other valid commit reference\&.
-.br
-\fB5. \fRYou can repeat steps 2\-4 multiple times to break the original code into any number of commits\&.
-.br
-\fB6. \fRNow you\(cqve split out many of the changes into their own commits, and might no longer use the patch mode of
+T}
+\fB5.\fR\h'-2n':T{
+You can repeat steps 2\-4 multiple times to break the original code into any number of commits\&.
+T}
+\fB6.\fR\h'-2n':T{
+Now you\(cqve split out many of the changes into their own commits, and might no longer use the patch mode of
\fBgit add\fR, in order to select all remaining uncommitted changes\&.
-.br
-\fB7. \fROnce again, check to verify that you\(cqve included what you want to\&. You may also wish to verify that git diff doesn\(cqt show any remaining changes to be committed later\&.
-.br
-\fB8. \fRAnd finally create the final commit\&.
-.br
+T}
+\fB7.\fR\h'-2n':T{
+Once again, check to verify that you\(cqve included what you want to\&. You may also wish to verify that git diff doesn\(cqt show any remaining changes to be committed later\&.
+T}
+\fB8.\fR\h'-2n':T{
+And finally create the final commit\&.
+T}
+.TE
.RE
.SH "DISCUSSION"
.sp