Skip to content

Commit a6fa2a8

Browse files
committed
Merge branch 'mg/reset-doc'
* mg/reset-doc: git-reset.txt: make modes description more consistent git-reset.txt: point to git-checkout git-reset.txt: use "working tree" consistently git-reset.txt: reset --soft is not a no-op git-reset.txt: reset does not change files in target git-reset.txt: clarify branch vs. branch head
2 parents 90215bf + d537c74 commit a6fa2a8

File tree

1 file changed

+47
-29
lines changed

1 file changed

+47
-29
lines changed

Documentation/git-reset.txt

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ SYNOPSIS
1515
DESCRIPTION
1616
-----------
1717
In the first and second form, copy entries from <commit> to the index.
18-
In the third form, set the current branch to <commit>, optionally
19-
modifying index and worktree to match. The <commit> defaults to HEAD
18+
In the third form, set the current branch head (HEAD) to <commit>, optionally
19+
modifying index and working tree to match. The <commit> defaults to HEAD
2020
in all forms.
2121

2222
'git reset' [-q] [<commit>] [--] <paths>...::
2323
This form resets the index entries for all <paths> to their
24-
state at the <commit>. (It does not affect the worktree, nor
24+
state at <commit>. (It does not affect the working tree, nor
2525
the current branch.)
2626
+
2727
This means that `git reset <paths>` is the opposite of `git add
2828
<paths>`.
29+
+
30+
After running `git reset <paths>` to update the index entry, you can
31+
use linkgit:git-checkout[1] to check the contents out of the index to
32+
the working tree.
33+
Alternatively, using linkgit:git-checkout[1] and specifying a commit, you
34+
can copy the contents of a path out of a commit to the index and to the
35+
working tree in one go.
2936

3037
'git reset' --patch|-p [<commit>] [--] [<paths>...]::
3138
Interactively select hunks in the difference between the index
@@ -36,39 +43,48 @@ This means that `git reset -p` is the opposite of `git add -p` (see
3643
linkgit:git-add[1]).
3744

3845
'git reset' [--<mode>] [<commit>]::
39-
This form points the current branch to <commit> and then
40-
updates index and working tree according to <mode>, which must
41-
be one of the following:
46+
This form resets the current branch head to <commit> and
47+
possibly updates the index (resetting it to the tree of <commit>) and
48+
the working tree depending on <mode>, which
49+
must be one of the following:
4250
+
4351
--
4452
--soft::
45-
Does not touch the index file nor the working tree at all, but
46-
requires them to be in a good order. This leaves all your changed
47-
files "Changes to be committed", as 'git status' would
48-
put it.
53+
Does not touch the index file nor the working tree at all (but
54+
resets the head to <commit>, just like all modes do). This leaves
55+
all your changed files "Changes to be committed", as 'git status'
56+
would put it.
4957

5058
--mixed::
5159
Resets the index but not the working tree (i.e., the changed files
5260
are preserved but not marked for commit) and reports what has not
5361
been updated. This is the default action.
5462

5563
--hard::
56-
Matches the working tree and index to that of the tree being
57-
switched to. Any changes to tracked files in the working tree
58-
since <commit> are lost.
64+
Resets the index and working tree. Any changes to tracked files in the
65+
working tree since <commit> are discarded.
5966

6067
--merge::
61-
Resets the index to match the tree recorded by the named commit,
62-
and updates the files that are different between the named commit
63-
and the current commit in the working tree.
68+
Resets the index and updates the files in the working tree that are
69+
different between <commit> and HEAD, but keeps those which are
70+
different between the index and working tree (i.e. which have changes
71+
which have not been added).
72+
If a file that is different between <commit> and the index has unstaged
73+
changes, reset is aborted.
74+
+
75+
In other words, --merge does something like a 'git read-tree -u -m <commit>',
76+
but carries forward unmerged index entries.
6477

6578
--keep::
66-
Reset the index to the given commit, keeping local changes in
67-
the working tree since the current commit, while updating
68-
working tree files without local changes to what appears in
69-
the given commit. If a file that is different between the
70-
current commit and the given commit has local changes, reset
71-
is aborted.
79+
Resets the index, updates files in the working tree that are
80+
different between <commit> and HEAD, but keeps those
81+
which are different between HEAD and the working tree (i.e.
82+
which have local changes).
83+
If a file that is different between <commit> and HEAD has local changes,
84+
reset is aborted.
85+
+
86+
In other words, --keep does a 2-way merge between <commit> and HEAD followed by
87+
'git reset --mixed <commit>'.
7288
--
7389

7490
If you want to undo a commit other than the latest on a branch,
@@ -184,7 +200,7 @@ tip of the current branch in ORIG_HEAD, so resetting hard to it
184200
brings your index file and the working tree back to that state,
185201
and resets the tip of the branch to that commit.
186202

187-
Undo a merge or pull inside a dirty work tree::
203+
Undo a merge or pull inside a dirty working tree::
188204
+
189205
------------
190206
$ git pull <1>
@@ -257,7 +273,7 @@ Suppose you are working on something and you commit it, and then you
257273
continue working a bit more, but now you think that what you have in
258274
your working tree should be in another branch that has nothing to do
259275
with what you committed previously. You can start a new branch and
260-
reset it while keeping the changes in your work tree.
276+
reset it while keeping the changes in your working tree.
261277
+
262278
------------
263279
$ git tag start
@@ -294,8 +310,10 @@ In these tables, A, B, C and D are some different states of a
294310
file. For example, the first line of the first table means that if a
295311
file is in state A in the working tree, in state B in the index, in
296312
state C in HEAD and in state D in the target, then "git reset --soft
297-
target" will put the file in state A in the working tree, in state B
298-
in the index and in state D in HEAD.
313+
target" will leave the file in the working tree in state A and in the
314+
index in state B. It resets (i.e. moves) the HEAD (i.e. the tip of
315+
the current branch, if you are on one) to "target" (which has the file
316+
in state D).
299317

300318
working index HEAD target working index HEAD
301319
----------------------------------------------------
@@ -346,11 +364,11 @@ in the index and in state D in HEAD.
346364
--keep B C C
347365

348366
"reset --merge" is meant to be used when resetting out of a conflicted
349-
merge. Any mergy operation guarantees that the work tree file that is
367+
merge. Any mergy operation guarantees that the working tree file that is
350368
involved in the merge does not have local change wrt the index before
351-
it starts, and that it writes the result out to the work tree. So if
369+
it starts, and that it writes the result out to the working tree. So if
352370
we see some difference between the index and the target and also
353-
between the index and the work tree, then it means that we are not
371+
between the index and the working tree, then it means that we are not
354372
resetting out from a state that a mergy operation left after failing
355373
with a conflict. That is why we disallow --merge option in this case.
356374

0 commit comments

Comments
 (0)