Skip to content

Commit 9813aac

Browse files
committed
Merge branch 'je/doc-reset'
Documentation updates. * je/doc-reset: doc: git-reset: clarify `git reset <pathspec>` doc: git-reset: clarify `git reset [mode]` doc: git-reset: clarify intro doc: git-reset: reorder the forms
2 parents 6edbb7b + 555c846 commit 9813aac

File tree

1 file changed

+57
-54
lines changed

1 file changed

+57
-54
lines changed

Documentation/git-reset.adoc

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,67 @@ git-reset(1)
33

44
NAME
55
----
6-
git-reset - Reset current HEAD to the specified state
6+
git-reset - Set `HEAD` or the index to a known state
77

88
SYNOPSIS
99
--------
1010
[synopsis]
11+
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
1112
git reset [-q] [<tree-ish>] [--] <pathspec>...
1213
git reset [-q] [--pathspec-from-file=<file> [--pathspec-file-nul]] [<tree-ish>]
1314
git reset (--patch | -p) [<tree-ish>] [--] [<pathspec>...]
14-
git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
1515

1616
DESCRIPTION
1717
-----------
18-
In the first three forms, copy entries from _<tree-ish>_ to the index.
19-
In the last form, set the current branch head (`HEAD`) to _<commit>_,
20-
optionally modifying index and working tree to match.
21-
The _<tree-ish>_/_<commit>_ defaults to `HEAD` in all forms.
22-
23-
`git reset [-q] [<tree-ish>] [--] <pathspec>...`::
24-
`git reset [-q] [--pathspec-from-file=<file> [--pathspec-file-nul]] [<tree-ish>]`::
25-
These forms reset the index entries for all paths that match the
26-
_<pathspec>_ to their state at _<tree-ish>_. (It does not affect
27-
the working tree or the current branch.)
28-
+
29-
This means that `git reset <pathspec>` is the opposite of `git add
30-
<pathspec>`. This command is equivalent to
31-
`git restore [--source=<tree-ish>] --staged <pathspec>...`.
32-
+
33-
After running `git reset <pathspec>` to update the index entry, you can
34-
use linkgit:git-restore[1] to check the contents out of the index to
35-
the working tree. Alternatively, using linkgit:git-restore[1]
36-
and specifying a commit with `--source`, you
37-
can copy the contents of a path out of a commit to the index and to the
38-
working tree in one go.
18+
`git reset` does either of the following:
3919

40-
`git reset (--patch | -p) [<tree-ish>] [--] [<pathspec>...]`::
41-
Interactively select hunks in the difference between the index
42-
and _<tree-ish>_ (defaults to `HEAD`). The chosen hunks are applied
43-
in reverse to the index.
44-
+
45-
This means that `git reset -p` is the opposite of `git add -p`, i.e.
46-
you can use it to selectively reset hunks. See the "Interactive Mode"
47-
section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
20+
1. `git reset [<mode>] <commit>` changes which commit `HEAD` points to. This
21+
makes it possible to undo various Git operations, for example commit, merge,
22+
rebase, and pull.
23+
2. When you specify files or directories or pass `--patch`, `git reset` updates
24+
the staged version of the specified files.
4825
4926
`git reset [<mode>] [<commit>]`::
50-
This form resets the current branch head to _<commit>_ and
51-
possibly updates the index (resetting it to the tree of _<commit>_) and
52-
the working tree depending on _<mode>_. Before the operation, `ORIG_HEAD`
53-
is set to the tip of the current branch. If _<mode>_ is omitted,
54-
defaults to `--mixed`. The _<mode>_ must be one of the following:
27+
Set the current branch head (`HEAD`) to point at _<commit>_.
28+
Depending on _<mode>_, also update the working directory and/or index
29+
to match the contents of _<commit>_.
30+
_<commit>_ defaults to `HEAD`.
31+
Before the operation, `ORIG_HEAD` is set to the tip of the current branch.
32+
+
33+
The _<mode>_ must be one of the following (default `--mixed`):
5534
+
56-
--
57-
`--soft`::
58-
Does not touch the index file or the working tree at all (but
59-
resets the head to _<commit>_, just like all modes do). This leaves
60-
all your changed files "Changes to be committed", as `git status`
61-
would put it.
6235

36+
--
6337
`--mixed`::
64-
Resets the index but not the working tree (i.e., the changed files
65-
are preserved but not marked for commit) and reports what has not
66-
been updated. This is the default action.
38+
Leave your working directory unchanged.
39+
Update the index to match the new `HEAD`, so nothing will be staged.
6740
+
68-
If `-N` is specified, removed paths are marked as intent-to-add (see
41+
If `-N` is specified, mark removed paths as intent-to-add (see
6942
linkgit:git-add[1]).
7043

44+
`--soft`::
45+
Leave your working tree files and the index unchanged.
46+
For example, if you have no staged changes, you can use
47+
`git reset --soft HEAD~5; git commit`
48+
to combine the last 5 commits into 1 commit. This works even with
49+
changes in the working tree, which are left untouched, but such usage
50+
can lead to confusion.
51+
7152
`--hard`::
72-
Resets the index and working tree. Any changes to tracked files in the
73-
working tree since _<commit>_ are discarded. Any untracked files or
74-
directories in the way of writing any tracked files are simply deleted.
53+
Overwrite all files and directories with the version from _<commit>_,
54+
and may overwrite untracked files. Tracked files not in _<commit>_ are
55+
removed so that the working tree matches _<commit>_.
56+
Update the index to match the new `HEAD`, so nothing will be staged.
7557

7658
`--merge`::
77-
Resets the index and updates the files in the working tree that are
78-
different between _<commit>_ and `HEAD`, but keeps those which are
59+
Reset the index and update the files in the working tree that are
60+
different between _<commit>_ and `HEAD`, but keep those which are
7961
different between the index and working tree (i.e. which have changes
8062
which have not been added).
63+
Mainly exists to reset unmerged index entries, like those left behind by
64+
`git am -3` or `git switch -m` in certain situations.
8165
If a file that is different between _<commit>_ and the index has
8266
unstaged changes, reset is aborted.
83-
+
84-
In other words, `--merge` does something like a `git read-tree -u -m <commit>`,
85-
but carries forward unmerged index entries.
8667

8768
`--keep`::
8869
Resets index entries and updates files in the working tree that are
@@ -98,6 +79,28 @@ but carries forward unmerged index entries.
9879
the submodules' `HEAD` to be detached at that commit.
9980
--
10081

82+
`git reset [-q] [<tree-ish>] [--] <pathspec>...`::
83+
`git reset [-q] [--pathspec-from-file=<file> [--pathspec-file-nul]] [<tree-ish>]`::
84+
For all specified files or directories, set the staged version to
85+
the version from the given commit or tree (which defaults to `HEAD`).
86+
+
87+
This means that `git reset <pathspec>` is the opposite of `git add
88+
<pathspec>`: it unstages all changes to the specified file(s) or
89+
directories. This is equivalent to `git restore --staged <pathspec>...`.
90+
+
91+
In this mode, `git reset` updates only the index (without updating the `HEAD` or
92+
working tree files). If you want to update the files as well as the index
93+
entries, use linkgit:git-restore[1].
94+
95+
`git reset (--patch | -p) [<tree-ish>] [--] [<pathspec>...]`::
96+
Interactively select changes from the difference between the index
97+
and the specified commit or tree (which defaults to `HEAD`).
98+
The index is modified using the chosen changes.
99+
+
100+
This means that `git reset -p` is the opposite of `git add -p`, i.e.
101+
you can use it to selectively unstage changes. See the "Interactive Mode"
102+
section of linkgit:git-add[1] to learn how to use the `--patch` option.
103+
101104
See "Reset, restore and revert" in linkgit:git[1] for the differences
102105
between the three commands.
103106

0 commit comments

Comments
 (0)